Sha256: 6334a61fbc95fe72a1cb8d651266f827012c1573f09d91f0ce1f3ab5cae074d6

Contents?: true

Size: 1.63 KB

Versions: 41

Compression:

Stored size: 1.63 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,
        :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 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

41 entries across 41 versions & 4 rubygems

Version Path
vagrantup-0.8.6 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.8.5 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.8.4 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.8.3 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.8.2 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.8.1 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.8.0 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.7.8 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.7.7 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.7.6 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.7.5 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.7.4 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.7.3 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.7.2 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.7.1 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.7.0 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.6.9 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.6.8 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.6.7 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.6.6 test/vagrant/action/vm/forward_ports_helpers_test.rb