Sha256: 1f38086b2d76717aa9d2d48f47f36931c8bacd1274ce9f9b644dc99f7342b424

Contents?: true

Size: 1.83 KB

Versions: 48

Compression:

Stored size: 1.83 KB

Contents

require "test_helper"

class ForwardPortsHelpersVMActionTest < Test::Unit::TestCase
  setup do
    @klass = Class.new do
      include Vagrant::Action::VM::ForwardPortsHelpers
      def initialize(env); @env = env; end
    end

    @app, @env = action_env

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

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

  context "getting list of used ports" do
    setup do
      @vms = []
      VirtualBox::VM.stubs(:all).returns(@vms)
      VirtualBox.stubs(:version).returns("3.1.0")
      @vm.stubs(:uuid).returns(:bar)
    end

    def mock_vm(options={})
      options = {
        :running? => true,
        :accessible? => true,
        :uuid => :foo
      }.merge(options)

      vm = mock("vm")
      options.each do |k,v|
        vm.stubs(k).returns(v)
      end

      vm
    end

    def mock_fp(hostport)
      fp = mock("fp")
      fp.stubs(:hostport).returns(hostport.to_s)
      fp
    end

    should "ignore VMs which aren't running" do
      @vms << mock_vm(:running? => false)
      @vms[0].expects(:forwarded_ports).never
      @instance.used_ports
    end

    should "ignore VMs which aren't accessible" do
      @vms << mock_vm(:accessible? => false)
      @vms[0].expects(:forwarded_ports).never
      @instance.used_ports
    end

    should "ignore VMs of the same uuid" do
      @vms << mock_vm(:uuid => @vm.uuid)
      @vms[0].expects(:forwarded_ports).never
      @instance.used_ports
    end

    should "return the forwarded ports for VB 3.2.x" do
      VirtualBox.stubs(:version).returns("3.2.4")
      fps = [mock_fp(2222), mock_fp(80)]
      na = mock("na")
      ne = mock("ne")
      na.stubs(:nat_driver).returns(ne)
      ne.stubs(:forwarded_ports).returns(fps)
      @vms << mock_vm(:network_adapters => [na])
      assert_equal [2222, 80], @instance.used_ports
    end
  end
end

Version data entries

48 entries across 48 versions & 7 rubygems

Version Path
bmhatfield-vagrant-1.0.10 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
bmhatfield-vagrant-1.0.9 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
bmhatfield-vagrant-1.0.8 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
bmhatfield-vagrant-1.0.7 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-1.0.7 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-1.0.6 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-1.0.5 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-1.0.4 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-1.0.3 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-1.0.2 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-1.0.1 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-1.0.0 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.9.99.2 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.9.99.1 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.9.7 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.9.6 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.9.5 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.9.4 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.9.3 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.9.2 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb