Test overriding ports works properly

This commit is contained in:
Mitchell Hashimoto 2012-01-08 23:29:40 -08:00
parent 29eb419c86
commit d430d62941
1 changed files with 36 additions and 16 deletions

View File

@ -20,25 +20,7 @@ describe "vagrant port forwarding" do
env.execute("vagrant", "box", "add", "base", box_path("default")).should succeed
end
it "forwards ports properly" do
initialize_environment
guest_port = 3000
host_port = 5000
environment.workdir.join("Vagrantfile").open("w+") do |f|
f.puts(<<VFILE)
Vagrant::Config.run do |config|
config.vm.box = "base"
config.vm.forward_port #{guest_port}, #{host_port}
end
VFILE
end
assert_execute("vagrant", "up")
thr = nil
begin
def assert_port_forwarded_properly(guest_port, host_port)
# Start up a web server in another thread by SSHing into the VM.
thr = Thread.new do
assert_execute("vagrant", "ssh", "-c", "python -m SimpleHTTPServer #{guest_port}")
@ -55,6 +37,44 @@ VFILE
# The server needs to die. This is how.
thr.kill if thr
end
it "forwards ports properly" do
initialize_environment
guest_port = 3000
host_port = 5000
environment.workdir.join("Vagrantfile").open("w+") do |f|
f.puts(<<VFILE)
Vagrant::Config.run do |config|
config.vm.box = "base"
config.vm.forward_port #{guest_port}, #{host_port}
end
VFILE
end
assert_execute("vagrant", "up")
assert_port_forwarded_properly(guest_port, host_port)
end
it "properly overrides port forwarding from the same port" do
initialize_environment
guest_port = 3000
host_port = 5000
environment.workdir.join("Vagrantfile").open("w+") do |f|
f.puts(<<VFILE)
Vagrant::Config.run do |config|
config.vm.box = "base"
config.vm.forward_port #{guest_port}, #{host_port - 1}
config.vm.forward_port #{guest_port}, #{host_port}
end
VFILE
end
assert_execute("vagrant", "up")
assert_port_forwarded_properly(guest_port, host_port)
end
it "detects and corrects port collisions" do