Ensure non-existent machines do not attempt to list snapshots

Prior to this commit, if a snapshot restore was run on an entire
environment with some non-existent guests, Vagrant would attempt to list
their snapshots with a nil id. This commit fixes that by returning an
empty list of snapshots if the machine has not been created yet.
This commit is contained in:
Brian Cain 2019-04-09 13:11:19 -07:00
parent 1fe8712ec2
commit 75d4aa42a1
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
2 changed files with 16 additions and 0 deletions

View File

@ -29,6 +29,7 @@ module VagrantPlugins
#
# @return [Array<String>] Snapshot Name
def self.snapshot_list(machine)
return [] if machine.id.nil?
machine.provider.driver.list_snapshots(machine.id)
end
end

View File

@ -40,4 +40,19 @@ describe VagrantPlugins::ProviderVirtualBox::Cap do
expect(described_class.forwarded_ports(machine)).to be(nil)
end
end
describe "#snapshot_list" do
it "returns all the snapshots" do
allow(machine).to receive(:id).and_return("1234")
allow(driver).to receive(:list_snapshots).with(machine.id).
and_return(["backup", "old"])
expect(described_class.snapshot_list(machine)).to eq(["backup", "old"])
end
it "returns empty array when the machine is does not exist" do
allow(machine).to receive(:id).and_return(nil)
expect(described_class.snapshot_list(machine)).to eq([])
end
end
end