From f7275f5113ada50231b034bb10467546b52cd45d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 24 Dec 2011 17:59:10 -0800 Subject: [PATCH] Test port forwarding basics --- test/acceptance/port_forward_test.rb | 51 +++++++++++++++++++ .../support/isolated_environment.rb | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/acceptance/port_forward_test.rb diff --git a/test/acceptance/port_forward_test.rb b/test/acceptance/port_forward_test.rb new file mode 100644 index 000000000..ad9ae7b50 --- /dev/null +++ b/test/acceptance/port_forward_test.rb @@ -0,0 +1,51 @@ +require File.expand_path("../base", __FILE__) + +require "net/http" +require "uri" + +require "vagrant/util/retryable" + +require "acceptance/support/shared/command_examples" + +describe "vagrant port forwarding" do + include Vagrant::Util::Retryable + + include_context "acceptance" + + it "forwards ports properly" do + require_box("default") + + guest_port = 3000 + host_port = 5000 + + environment.workdir.join("Vagrantfile").open("w+") do |f| + f.puts(< 5, :sleep => 2) do + # Verify that port forwarding works by making a simple HTTP request + # to the port. We should get a 200 response. + result = Net::HTTP.get_response(URI.parse("http://localhost:#{host_port}/")) + result.code.should == "200" + end + ensure + # The server needs to die. This is how. + thr.kill if thr + end + end +end diff --git a/test/acceptance/support/isolated_environment.rb b/test/acceptance/support/isolated_environment.rb index a36df8c87..d30ab8b24 100644 --- a/test/acceptance/support/isolated_environment.rb +++ b/test/acceptance/support/isolated_environment.rb @@ -86,7 +86,7 @@ module Acceptance sleep 0.5 result = execute("VBoxManage", "unregistervm", data[:uuid], "--delete") - raise Exception, "VM unregistration failed!" if result.exit_status != 0 + raise Exception, "VM unregistration failed!" if result.exit_code != 0 end @logger.info("Removed all virtual machines")