From bb2f3b35b9c1dd042208e14fa5e6afb11ca0d05b Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 9 Mar 2018 13:06:26 -0800 Subject: [PATCH] Add basic unit test --- plugins/kernel_v2/config/trigger.rb | 4 ++ .../plugins/kernel_v2/config/trigger_test.rb | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 test/unit/plugins/kernel_v2/config/trigger_test.rb diff --git a/plugins/kernel_v2/config/trigger.rb b/plugins/kernel_v2/config/trigger.rb index 1e6d39e06..882953154 100644 --- a/plugins/kernel_v2/config/trigger.rb +++ b/plugins/kernel_v2/config/trigger.rb @@ -97,6 +97,8 @@ module VagrantPlugins # Validate Trigger settings def validate(machine) + errors = _detected_errors + if !@run.nil? # validate proper keys # WARN if invalid keys are used? @@ -106,6 +108,8 @@ module VagrantPlugins # validate proper keys # WARN if invalid keys are used? end + + {"triggers" => errors} end # The String representation of this Trigger. diff --git a/test/unit/plugins/kernel_v2/config/trigger_test.rb b/test/unit/plugins/kernel_v2/config/trigger_test.rb new file mode 100644 index 000000000..be7d1a6c1 --- /dev/null +++ b/test/unit/plugins/kernel_v2/config/trigger_test.rb @@ -0,0 +1,40 @@ +require File.expand_path("../../../../base", __FILE__) + +require Vagrant.source_root.join("plugins/kernel_v2/config/trigger") + +describe VagrantPlugins::Kernel_V2::TriggerConfig do + include_context "unit" + + subject { described_class.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 + + before do + env = double("env") + allow(env).to receive(:root_path).and_return(nil) + allow(machine).to receive(:env).and_return(env) + allow(machine).to receive(:provider_config).and_return(nil) + allow(machine).to receive(:provider_options).and_return({}) + + subject.name = "foo" + end + + it "is valid with test defaults" do + subject.finalize! + assert_valid + end +end