Merge pull request #9784 from briancain/move-trigger-obj-init

Move triggers object init in machine
This commit is contained in:
Brian Cain 2018-05-04 15:00:19 -07:00 committed by GitHub
commit f43cacd36a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -110,6 +110,7 @@ module Vagrant
@ui = Vagrant::UI::Prefixed.new(@env.ui, @name)
@ui_mutex = Mutex.new
@state_mutex = Mutex.new
@triggers = Vagrant::Plugin::V2::Trigger.new(@env, @config.trigger, self)
# Read the ID, which is usually in local storage
@id = nil
@ -149,8 +150,6 @@ module Vagrant
# Output a bunch of information about this machine in
# machine-readable format in case someone is listening.
@ui.machine("metadata", "provider", provider_name)
@triggers = Vagrant::Plugin::V2::Trigger.new(@env, @config.trigger, self)
end
# This calls an action on the provider. The provider may or may not

View File

@ -50,7 +50,8 @@ describe Vagrant::Machine do
def new_provider_mock
double("provider").tap do |obj|
allow(obj).to receive(:_initialize).and_return(nil)
allow(obj).to receive(:_initialize)
.with(provider_name, anything).and_return(nil)
allow(obj).to receive(:machine_id_changed).and_return(nil)
allow(obj).to receive(:state).and_return(Vagrant::MachineState.new(
:created, "", ""))
@ -76,6 +77,24 @@ describe Vagrant::Machine do
expect(subject.id).to be_nil
end
context "setting up triggers" do
before do
expect(provider).to receive(:_initialize) do |*args|
machine = args.last
@trigger_instance = machine.instance_variable_get(:@triggers)
true
end
end
it "should initialize the trigger object" do
subject = new_instance
expect(subject.instance_variable_get(:@triggers))
.to be_a(Vagrant::Plugin::V2::Trigger)
expect(subject.instance_variable_get(:@triggers))
.to eq(@trigger_instance)
end
end
describe "as a base" do
let(:base) { true}