Sha256: 057273021a485ad7884a546dfef5067b7bcc306521635995a9e8c50a0ff17e5f

Contents?: true

Size: 1.7 KB

Versions: 42

Compression:

Stored size: 1.7 KB

Contents

require "test_helper"

class ClearForwardedPortsVMActionTest < Test::Unit::TestCase
  setup do
    @klass = Vagrant::Action::VM::ClearForwardedPorts
    @app, @env = action_env

    @vm = mock("vm")
    @vm.stubs(:name).returns("foo")
    @env["vm"] = @vm

    @instance = @klass.new(@app, @env)
  end

  context "calling" do
    should "call the proper methods and continue chain" do
      seq = sequence('seq')
      @instance.expects(:clear).in_sequence(seq)
      @app.expects(:call).with(@env).in_sequence(seq)
      @instance.call(@env)
    end
  end

  context "clearing forwarded ports" do
    setup do
      @instance.stubs(:used_ports).returns([:a])
      @instance.stubs(:clear_ports)
    end

    should "call destroy on all forwarded ports" do
      @instance.expects(:clear_ports).once
      @vm.expects(:reload!)
      @instance.clear
    end

    should "do nothing if there are no forwarded ports" do
      @instance.stubs(:used_ports).returns([])
      @vm.expects(:reload!).never
      @instance.clear
    end
  end

  context "clearing ports" do
    def mock_fp
      fp = mock("fp")
      fp.expects(:destroy).once
      fp
    end

    setup do
      VirtualBox.stubs(:version).returns("3.2.8")
      @adapters = []
      @internal_vm = mock("internal_vm")
      @internal_vm.stubs(:network_adapters).returns(@adapters)
      @vm.stubs(:vm).returns(@internal_vm)
    end

    def mock_adapter
      na = mock("adapter")
      engine = mock("engine")
      engine.stubs(:forwarded_ports).returns([mock_fp])
      na.stubs(:nat_driver).returns(engine)
      na
    end

    should "destroy each forwarded port" do
      @adapters << mock_adapter
      @adapters << mock_adapter
      @instance.clear_ports
    end
  end
end

Version data entries

42 entries across 42 versions & 4 rubygems

Version Path
vagrantup-0.7.8 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.7.7 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.7.6 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.7.5 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.7.4 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.7.3 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.7.2 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.7.1 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.7.0 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.6.9 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.6.8 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.6.7 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.6.6 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.6.5 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.6.4 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.6.3 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.6.2 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.6.1 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrantup-0.6.0 test/vagrant/action/vm/clear_forwarded_ports_test.rb
vagrant-0.7.8 test/vagrant/action/vm/clear_forwarded_ports_test.rb