mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Ensure the machine data_dir is recreated after removal because vagrant up expects the directory to exist even if there has been an exception and the machine has been deleted subsequently.
59 lines
1.7 KiB
Ruby
59 lines
1.7 KiB
Ruby
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
|
|
before do
|
|
FileUtils.touch(File.join(machine.data_dir, "box.meta"))
|
|
end
|
|
|
|
context 'with default options' do
|
|
it 'should verbosely remove the folder' do
|
|
expect(ui).to receive(:info).with('Deleting the machine folder')
|
|
|
|
expect(subject.call(env)).to be_nil
|
|
|
|
expect(File.exists?(machine.data_dir)).to eq(true)
|
|
expect(Dir.entries(machine.data_dir)).to match_array([".", ".."])
|
|
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(3).times
|
|
end
|
|
end
|
|
|
|
it 'should remove the folder' do
|
|
expect(ui).to receive(:info).with('Deleting the machine folder')
|
|
|
|
expect(subject.call(env)).to be_nil
|
|
|
|
expect(File.exists?(machine.data_dir)).to eq(true)
|
|
expect(Dir.entries(machine.data_dir)).to match_array([".", ".."])
|
|
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(subject.call(env)).to be_nil
|
|
|
|
expect(File.exists?(machine.data_dir)).to eq(true)
|
|
expect(Dir.entries(machine.data_dir)).to match_array([".", ".."])
|
|
end
|
|
end
|
|
end
|
|
end
|