Add basic unit test

This commit is contained in:
Brian Cain 2018-03-09 13:06:26 -08:00
parent 7cccddc009
commit bb2f3b35b9
No known key found for this signature in database
GPG Key ID: 43D51080D357A001
2 changed files with 44 additions and 0 deletions

View File

@ -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.

View File

@ -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