diff --git a/plugins/kernel_v2/config/vm_trigger.rb b/plugins/kernel_v2/config/vm_trigger.rb index edee528ba..c0220f4ea 100644 --- a/plugins/kernel_v2/config/vm_trigger.rb +++ b/plugins/kernel_v2/config/vm_trigger.rb @@ -101,13 +101,13 @@ module VagrantPlugins # Guests are stored internally as strings if !@only_on.nil? @only_on = Array(@only_on) - @only_on.map { |o| o.to_s } + @only_on.map! { |o| o.to_s } end # Commands must be stored internally as symbols if !@ignore.nil? @ignore = Array(@ignore) - @ignore.map { |i| i.to_sym } + @ignore.map! { |i| i.to_sym } end # Convert @run and @run_remote to be a "Shell provisioner" config diff --git a/test/unit/plugins/kernel_v2/config/vm_trigger_test.rb b/test/unit/plugins/kernel_v2/config/vm_trigger_test.rb index 71a04bb4b..da4b7f108 100644 --- a/test/unit/plugins/kernel_v2/config/vm_trigger_test.rb +++ b/test/unit/plugins/kernel_v2/config/vm_trigger_test.rb @@ -46,4 +46,71 @@ describe VagrantPlugins::Kernel_V2::VagrantConfigTrigger do end end + describe "defining a new config that needs to match internal restraints" do + let(:cmd) { :destroy } + let(:cfg) { described_class.new(cmd) } + let(:arr_cfg) { described_class.new(cmd) } + + before do + cfg.only_on = :guest + cfg.ignore = "up" + arr_cfg.only_on = [:guest, :other] + arr_cfg.ignore = ["up", "destroy"] + end + + it "ensures only_on is an array of strings" do + cfg.finalize! + arr_cfg.finalize! + + expect(cfg.only_on).to be_a(Array) + expect(arr_cfg.only_on).to be_a(Array) + + cfg.only_on.each do |a| + expect(a).to be_a(String) + end + + arr_cfg.only_on.each do |a| + expect(a).to be_a(String) + end + end + + it "ensures ignore is an array of symbols" do + cfg.finalize! + arr_cfg.finalize! + + expect(cfg.ignore).to be_a(Array) + expect(arr_cfg.ignore).to be_a(Array) + + cfg.ignore.each do |a| + expect(a).to be_a(Symbol) + end + + arr_cfg.ignore.each do |a| + expect(a).to be_a(Symbol) + end + end + end + + describe "defining a basic trigger config" do + let(:cmd) { :up } + let(:cfg) { described_class.new(cmd) } + + before do + cfg.info = "Hello there" + cfg.warn = "Warning!!" + cfg.on_error = :continue + cfg.ignore = :up + cfg.only_on = "guest" + end + + it "sets the options" do + cfg.finalize! + expect(cfg.info).to eq("Hello there") + expect(cfg.warn).to eq("Warning!!") + expect(cfg.on_error).to eq(:continue) + expect(cfg.ignore).to eq([:up]) + expect(cfg.only_on).to eq(["guest"]) + end + end + end