Add cleanup_disks test

This commit is contained in:
Brian Cain 2020-01-23 09:10:31 -08:00
parent 9ca535dbfa
commit eff3d47f82
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
2 changed files with 58 additions and 0 deletions

View File

@ -14,6 +14,9 @@ module Vagrant
machine = env[:machine]
defined_disks = get_disks(machine, env)
# TODO: Maybe always cleanup disks, even if no disks are defined.
# Check meta file first
#
# Call into providers machine implementation for disk management
if !defined_disks.empty?
if machine.provider.capability?(:cleanup_disks)

View File

@ -0,0 +1,55 @@
require File.expand_path("../../../../base", __FILE__)
describe Vagrant::Action::Builtin::CleanupDisks do
let(:app) { lambda { |env| } }
let(:vm) { double("vm") }
let(:config) { double("config", vm: vm) }
let(:provider) { double("provider") }
let(:machine) { double("machine", config: config, provider: provider,
provider_name: "provider", data_dir: Pathname.new("/fake/dir")) }
let(:env) { { ui: ui, machine: machine} }
let(:disks) { [double("disk")] }
let(:ui) { double("ui") }
let(:disk_meta_file) { {disk: [{uuid: "123456789", name: "storage"}], floppy: [], dvd: []} }
describe "#call" do
it "calls configure_disks if disk config present" do
allow(vm).to receive(:disks).and_return(disks)
allow(machine).to receive(:disks).and_return(disks)
allow(machine.provider).to receive(:capability?).with(:cleanup_disks).and_return(true)
subject = described_class.new(app, env)
expect(app).to receive(:call).with(env).ordered
expect(subject).to receive(:read_disk_metadata).with(machine).and_return(disk_meta_file)
expect(machine.provider).to receive(:capability).
with(:cleanup_disks, disks, disk_meta_file)
subject.call(env)
end
it "continues on if no disk config present" do
allow(vm).to receive(:disks).and_return([])
subject = described_class.new(app, env)
expect(app).to receive(:call).with(env).ordered
expect(machine.provider).not_to receive(:capability).with(:cleanup_disks, disks)
subject.call(env)
end
it "prints a warning if disk config capability is unsupported" do
allow(vm).to receive(:disks).and_return(disks)
allow(machine.provider).to receive(:capability?).with(:cleanup_disks).and_return(false)
subject = described_class.new(app, env)
expect(app).to receive(:call).with(env).ordered
expect(machine.provider).not_to receive(:capability).with(:cleanup_disks, disks)
expect(ui).to receive(:warn)
subject.call(env)
end
end
end