2021-06-30 13:27:03 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2022-11-08 16:28:32 +00:00
|
|
|
require_relative '../../spec_helper'
|
2021-05-18 18:21:54 +01:00
|
|
|
|
|
|
|
|
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
|
2021-05-28 15:40:34 +01:00
|
|
|
before do
|
|
|
|
|
FileUtils.touch(File.join(machine.data_dir, "box.meta"))
|
|
|
|
|
end
|
|
|
|
|
|
2021-05-18 18:21:54 +01:00
|
|
|
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
|
2021-05-28 15:40:34 +01:00
|
|
|
|
2023-01-19 16:39:17 +09:00
|
|
|
expect(File.exist?(machine.data_dir)).to eq(true)
|
2021-05-28 15:40:34 +01:00
|
|
|
expect(Dir.entries(machine.data_dir)).to match_array([".", ".."])
|
2021-05-18 18:21:54 +01:00
|
|
|
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
|
2021-05-28 15:40:34 +01:00
|
|
|
expect(machine).to receive(:data_dir).and_return(d.to_s).exactly(3).times
|
2021-05-18 18:21:54 +01:00
|
|
|
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
|
2021-05-28 15:40:34 +01:00
|
|
|
|
2023-01-19 16:39:17 +09:00
|
|
|
expect(File.exist?(machine.data_dir)).to eq(true)
|
2021-05-28 15:40:34 +01:00
|
|
|
expect(Dir.entries(machine.data_dir)).to match_array([".", ".."])
|
2021-05-18 18:21:54 +01:00
|
|
|
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
|
2021-05-28 15:40:34 +01:00
|
|
|
|
2023-01-19 16:39:17 +09:00
|
|
|
expect(File.exist?(machine.data_dir)).to eq(true)
|
2021-05-28 15:40:34 +01:00
|
|
|
expect(Dir.entries(machine.data_dir)).to match_array([".", ".."])
|
2021-05-18 18:21:54 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|