From c8e3e2c80569a87569cecc8c6b2752c1060da18a Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Wed, 28 Sep 2022 18:17:18 +0100 Subject: [PATCH] Mock out synced folders for action tests (#1610) Allowing synced folders to be validated as part of the action tests can cause an excessive amount of time to be consumed due to many calls to systemd and distro packager to check if nfs is available on the host. --- spec/unit/action_spec.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/spec/unit/action_spec.rb b/spec/unit/action_spec.rb index 9f76449..623527c 100644 --- a/spec/unit/action_spec.rb +++ b/spec/unit/action_spec.rb @@ -22,10 +22,23 @@ describe VagrantPlugins::ProviderLibvirt::Action do allow(machine).to receive(:state).and_return(state) allow(logger).to receive(:info) + allow(logger).to receive(:trace) allow(logger).to receive(:debug) allow(logger).to receive(:error) allow(connection.client).to receive(:libversion).and_return(6_002_000) + + # patch out iterating synced_folders by emptying the list returned + # where vagrant us using a Collection, otherwise fallback to using + # the env value to disable the behaviour for older versions. + begin + require 'vagrant/plugin/v2/synced_folder' + + synced_folders = Vagrant::Plugin::V2::SyncedFolder::Collection.new + allow(machine).to receive(:synced_folders).and_return(synced_folders) + rescue NameError + env[:synced_folders_disable] = true + end end def allow_action_env_result(action, *responses) @@ -52,7 +65,7 @@ describe VagrantPlugins::ProviderLibvirt::Action do it 'should execute without error' do expect(ui).to receive(:info).with('Domain is not created. Please run `vagrant up` first.') - expect { runner.run(subject.action_halt) }.not_to raise_error + expect(runner.run(subject.action_halt)).to match(hash_including({:machine => machine})) end end @@ -74,7 +87,7 @@ describe VagrantPlugins::ProviderLibvirt::Action do expect(ui).to_not receive(:info).with('Domain is not created. Please run `vagrant up` first.') expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::HaltDomain).to_not receive(:call) - expect { runner.run(subject.action_halt) }.not_to raise_error + expect(runner.run(subject.action_halt)).to match(hash_including({:machine => machine})) end end @@ -87,7 +100,7 @@ describe VagrantPlugins::ProviderLibvirt::Action do it 'should call halt' do expect_any_instance_of(VagrantPlugins::ProviderLibvirt::Action::HaltDomain).to receive(:call) - expect { runner.run(subject.action_halt) }.not_to raise_error + expect(runner.run(subject.action_halt)).to match(hash_including({:machine => machine})) end end end