Ensure state is fully removed for destroy (#1288)

Completely remove state after a destroy, and ensure removal of a
non-existing domain also scrubs the machine folder clean.

Closes: #1132
This commit is contained in:
Darragh Bailey
2021-05-18 18:21:54 +01:00
committed by GitHub
parent 07391048af
commit 878b5ffe61
3 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
require 'spec_helper'
require 'support/sharedcontext'
require 'vagrant-libvirt/action/clean_machine_folder'
describe VagrantPlugins::ProviderLibvirt::Action::CleanMachineFolder do
subject { described_class.new(app, env) }
include_context 'unit'
describe '#call' do
context 'with default options' do
it 'should verbosely remove the folder' do
expect(ui).to receive(:info).with('Deleting the machine folder')
expect(FileUtils).to receive(:rm_rf).with(machine.data_dir, {:secure => true})
expect(subject.call(env)).to be_nil
end
end
context 'when the data dir doesn\'t exist' do
before do
Dir.mktmpdir do |d|
# returns a temporary directory that has been already deleted when running
expect(machine).to receive(:data_dir).and_return(d.to_s).exactly(2).times
end
end
it 'should remove the folder' do
expect(ui).to receive(:info).with('Deleting the machine folder')
expect(FileUtils).to receive(:rm_rf).with(machine.data_dir, {:secure => true})
expect(subject.call(env)).to be_nil
end
end
context 'with quiet option enabled' do
subject { described_class.new(app, env, {:quiet => true}) }
it 'should quietly remove the folder' do
expect(ui).to_not receive(:info).with('Deleting the machine folder')
expect(FileUtils).to receive(:rm_rf).with(machine.data_dir, {:secure => true})
expect(subject.call(env)).to be_nil
end
end
end
end