From 4372ab034e22e134f2d3c8e5307dd102241c9727 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 20 Apr 2014 08:52:09 -0700 Subject: [PATCH] providers/virtualbox: merge customizations properly --- plugins/providers/virtualbox/config.rb | 8 +++ .../providers/virtualbox/config_test.rb | 51 ++++++++++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/plugins/providers/virtualbox/config.rb b/plugins/providers/virtualbox/config.rb index be1d6040e..aed1c692c 100644 --- a/plugins/providers/virtualbox/config.rb +++ b/plugins/providers/virtualbox/config.rb @@ -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! diff --git a/test/unit/plugins/providers/virtualbox/config_test.rb b/test/unit/plugins/providers/virtualbox/config_test.rb index 63fc593d8..237eaa415 100644 --- a/test/unit/plugins/providers/virtualbox/config_test.rb +++ b/test/unit/plugins/providers/virtualbox/config_test.rb @@ -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)