providers/virtualbox: merge customizations properly

This commit is contained in:
Mitchell Hashimoto 2014-04-20 08:52:09 -07:00
parent 568185c3e9
commit 4372ab034e
2 changed files with 57 additions and 2 deletions

View File

@ -107,6 +107,14 @@ module VagrantPlugins
customize("pre-boot", ["modifyvm", :id, "--cpus", count.to_i])
end
def merge(other)
super.tap do |result|
c = customizations.dup
c += other.customizations
result.instance_variable_set(:@customizations, c)
end
end
# This is the hook that is called to finalize the object before it
# is put into use.
def finalize!

View File

@ -3,9 +3,40 @@ require_relative "../../../base"
require Vagrant.source_root.join("plugins/providers/virtualbox/config")
describe VagrantPlugins::ProviderVirtualBox::Config do
context "defaults" do
subject { VagrantPlugins::ProviderVirtualBox::Config.new }
let(:machine) { double("machine") }
def assert_invalid
errors = subject.validate(machine)
if !errors.values.any? { |v| !v.empty? }
raise "No errors: #{errors.inspect}"
end
end
def assert_valid
errors = subject.validate(machine)
if !errors.values.all? { |v| v.empty? }
raise "Errors: #{errors.inspect}"
end
end
def valid_defaults
subject.image = "foo"
end
before do
vm_config = double("vm_config")
vm_config.stub(networks: [])
config = double("config")
config.stub(vm: vm_config)
machine.stub(config: config)
end
its "valid by default" do
subject.finalize!
assert_valid
end
context "defaults" do
before { subject.finalize! }
it { expect(subject.check_guest_additions).to be_true }
@ -20,6 +51,22 @@ describe VagrantPlugins::ProviderVirtualBox::Config do
end
end
describe "#merge" do
let(:one) { described_class.new }
let(:two) { described_class.new }
subject { one.merge(two) }
it "merges the customizations" do
one.customize ["foo"]
two.customize ["bar"]
expect(subject.customizations).to eq([
["pre-boot", ["foo"]],
["pre-boot", ["bar"]]])
end
end
describe "#network_adapter" do
it "configures additional adapters" do
subject.network_adapter(2, :bridged, auto_config: true)