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:
parent
1fe8712ec2
commit
75d4aa42a1
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue