Fix port collision in tests
This commit is contained in:
parent
398017ba6e
commit
c1623ee740
|
@ -39,7 +39,10 @@ describe VagrantPlugins::FTPPush::FTPAdapter do
|
||||||
include_context "unit"
|
include_context "unit"
|
||||||
|
|
||||||
before(:all) do
|
before(:all) do
|
||||||
@server = FakeFtp::Server.new(21212, 21213)
|
@server = nil
|
||||||
|
with_random_port do |port1, port2|
|
||||||
|
@server = FakeFtp::Server.new(port1, port2)
|
||||||
|
end
|
||||||
@server.start
|
@server.start
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ describe VagrantPlugins::FTPPush::Push do
|
||||||
let(:env) { isolated_environment }
|
let(:env) { isolated_environment }
|
||||||
let(:config) do
|
let(:config) do
|
||||||
double("config",
|
double("config",
|
||||||
host: "127.0.0.1:51234",
|
host: "127.0.0.1:#{@port}",
|
||||||
username: "sethvargo",
|
username: "sethvargo",
|
||||||
password: "bacon",
|
password: "bacon",
|
||||||
passive: false,
|
passive: false,
|
||||||
|
@ -34,7 +34,11 @@ describe VagrantPlugins::FTPPush::Push do
|
||||||
|
|
||||||
describe "#push" do
|
describe "#push" do
|
||||||
before(:all) do
|
before(:all) do
|
||||||
@server = FakeFtp::Server.new(51234, 21213)
|
@server = nil
|
||||||
|
with_random_port do |port1, port2|
|
||||||
|
@port = port1
|
||||||
|
@server = FakeFtp::Server.new(port1, port2)
|
||||||
|
end
|
||||||
@server.start
|
@server.start
|
||||||
|
|
||||||
@dir = Dir.mktmpdir
|
@dir = Dir.mktmpdir
|
||||||
|
|
|
@ -116,4 +116,18 @@ shared_context "unit" do
|
||||||
ENV[key] = value
|
ENV[key] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This helper provides a randomly available port(s) for each argument to the
|
||||||
|
# block.
|
||||||
|
def with_random_port(&block)
|
||||||
|
ports = []
|
||||||
|
|
||||||
|
block.arity.times do
|
||||||
|
server = TCPServer.new('127.0.0.1', 0)
|
||||||
|
ports << server.addr[1]
|
||||||
|
server.close
|
||||||
|
end
|
||||||
|
|
||||||
|
block.call(*ports)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,8 +42,12 @@ describe Vagrant::Action::Builtin::BoxAdd do
|
||||||
tf = Tempfile.new("vagrant")
|
tf = Tempfile.new("vagrant")
|
||||||
tf.close
|
tf.close
|
||||||
|
|
||||||
port = 21212
|
port = nil
|
||||||
server = FakeFtp::Server.new(port, port+1)
|
server = nil
|
||||||
|
with_random_port do |port1, port2|
|
||||||
|
port = port1
|
||||||
|
server = FakeFtp::Server.new(port1, port2)
|
||||||
|
end
|
||||||
server.add_file(path.basename, path.read)
|
server.add_file(path.basename, path.read)
|
||||||
server.start
|
server.start
|
||||||
yield port
|
yield port
|
||||||
|
|
Loading…
Reference in New Issue