Sha256: 896207c3049c370ec851c0892c60ff15254607cdb6f57fca9c31eed0614c3790

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

require "test_helper"

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

    @klass.send(:include, Vagrant::Action::VM::ForwardPortsHelpers)
    @app, @env = mock_action_data

    @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 %W[2222 80], @instance.used_ports
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
vagrantup-0.5.4 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrantup-0.5.3 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrant-0.5.4 test/vagrant/action/vm/forward_ports_helpers_test.rb
vagrant-0.5.3 test/vagrant/action/vm/forward_ports_helpers_test.rb