Files
vagrant-libvirt/spec/unit/action/remove_libvirt_image_spec.rb
Darragh Bailey 9885e58c21 Update after hook definition for recent vagrant (#1506)
Vagrant newer than 2.2.11 reworked how the after hook definition
functions requiring it to be called in a different way to ensure it is
possible to hook the box remove action to perform the expected local
action.

Add a compatibility function to ensure that the plugin works with both
mechanisms and some simple tests to ensure that with the unit tests
validated against the older vagrant versions that it confirms the action
will be called as expected.

As part of fixing the call of the remove_libvirt_image action, ensure it
only executes when the box removed is a libvirt one and ignores all
others.

Fixes: #1196
2022-06-05 17:44:10 +01:00

44 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
require 'support/sharedcontext'
require 'vagrant-libvirt/action/remove_libvirt_image'
describe VagrantPlugins::ProviderLibvirt::Action::RemoveLibvirtImage do
subject { described_class.new(app, env) }
include_context 'unit'
let(:box) { instance_double(::Vagrant::Box) }
describe '#call' do
before do
env[:box_removed] = box
allow(ui).to receive(:info)
end
context 'when called with libvirt box removed' do
before do
expect(box).to receive(:provider).and_return(:libvirt)
end
it 'should notify the user about limited removal' do
expect(ui).to receive(:info).with(/Vagrant-libvirt plugin removed box/)
expect(subject.call(env)).to be_nil
end
end
context 'when called with any other provider box' do
before do
expect(box).to receive(:provider).and_return(:virtualbox)
end
it 'call the next middle ware immediately' do
expect(ui).to_not receive(:info).with(/Vagrant-libvirt plugin removed box/)
expect(subject.call(env)).to be_nil
end
end
end
end