mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
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:
48
spec/unit/action/clean_machine_folder_spec.rb
Normal file
48
spec/unit/action/clean_machine_folder_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user