From 22f085dc5d1f04e1d054d13f4193136b5c6b84d1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 8 Feb 2011 19:42:32 -0800 Subject: [PATCH] Tests for mac address setting on host only network --- lib/vagrant/action/vm/network.rb | 4 +-- test/vagrant/action/vm/network_test.rb | 38 ++++++++++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/vagrant/action/vm/network.rb b/lib/vagrant/action/vm/network.rb index f7acc0510..eaaed6a12 100644 --- a/lib/vagrant/action/vm/network.rb +++ b/lib/vagrant/action/vm/network.rb @@ -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 diff --git a/test/vagrant/action/vm/network_test.rb b/test/vagrant/action/vm/network_test.rb index f8d64fa0a..d33d7cf58 100644 --- a/test/vagrant/action/vm/network_test.rb +++ b/test/vagrant/action/vm/network_test.rb @@ -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