Tests for mac address setting on host only network

This commit is contained in:
Mitchell Hashimoto 2011-02-08 19:42:32 -08:00
parent e2d5c12870
commit 22f085dc5d
2 changed files with 30 additions and 12 deletions

View File

@ -65,9 +65,7 @@ module Vagrant
adapter.enabled = true
adapter.attachment_type = :host_only
adapter.host_interface = network_name(network_options)
if network_options[:mac]
adapter.mac_address = network_options[:mac].gsub(/:/, '')
end
adapter.mac_address = network_options[:mac].gsub(':', '') if network_options[:mac]
adapter.save
end
end

View File

@ -116,24 +116,44 @@ class NetworkVMActionTest < Test::Unit::TestCase
@network_adapters = []
@internal_vm.stubs(:network_adapters).returns(@network_adapters)
end
@options = {
def expect_adapter_setup(options=nil)
options = {
:ip => "foo",
:adapter => 7
}
}.merge(options || {})
@env.env.config.vm.network(@options[:ip], @options)
@env["config"].vm.network(options[:ip], options)
@env["vm"].vm.network_adapters.clear
@env["vm"].vm.network_adapters[options[:adapter]] = adapter = mock("adapter")
adapter.expects(:enabled=).with(true)
adapter.expects(:attachment_type=).with(:host_only).once
adapter.expects(:host_interface=).with(@network_name).once
if options[:mac]
adapter.expects(:mac_address=).with(options[:mac].gsub(':', '')).once
else
adapter.expects(:mac_address=).never
end
adapter.expects(:save).once
end
should "setup the specified network adapter" do
adapter = mock("adapter")
@network_adapters[@options[:adapter]] = adapter
expect_adapter_setup
@instance.assign_network
end
adapter.expects(:enabled=).with(true).once
adapter.expects(:attachment_type=).with(:host_only).once
adapter.expects(:host_interface=).with(@network_name).once
adapter.expects(:save).once
should "setup the specified network adapter's mac address if specified" do
expect_adapter_setup(:mac => "foo")
@instance.assign_network
end
should "properly remove : from mac address" do
expect_adapter_setup(:mac => "foo:bar")
@instance.assign_network
end
end