Merge pull request #12188 from soapy1/vagrant-does-not-reference-empty-string-vm

Don't try to find "" by prefix in the machine index
This commit is contained in:
Sophia Castellarin 2021-02-23 14:24:17 -06:00 committed by GitHub
commit d111596446
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 3 deletions

View File

@ -263,7 +263,7 @@ module Vagrant
#
# @return [Hash]
def find_by_prefix(prefix)
return if !prefix
return if !prefix || prefix == ""
@machines.each do |uuid, data|
return data.merge("id" => uuid) if uuid.start_with?(prefix)
end

View File

@ -164,11 +164,18 @@ describe VagrantPlugins::CommandDestroy::Command do
subject.execute
end
context "with an invalid argument" do
context "with machine that does not exist" do
let(:argv){ ["notweb"] }
it "raises an exception" do
expect { subject.execute }.to raise_error(Vagrant::Errors::MachineNotFound)
end
end
context "with an invalid argument" do
let(:argv){ [""] }
it "raises an exception" do
expect { subject.execute }.to raise_error(Vagrant::Errors::MachineNotFound)
end
end
end
end

View File

@ -108,6 +108,11 @@ describe Vagrant::MachineIndex do
expect(subject.get(nil)).to be_nil
end
it "returns nil if the machine doesn't exist (is an empty string)" do
expect(subject.get("")).to be_nil
expect(subject.get(nil)).to be_nil
end
it "returns a valid entry if the machine exists" do
result = subject.get("bar")
@ -144,7 +149,6 @@ describe Vagrant::MachineIndex do
expect(subject.include?(nil)).to be(false)
end
it "locks the entry so subsequent gets fail" do
result = subject.get("bar")
expect(result).to_not be_nil