Merge pull request #13320 from hashicorp/box-collection-sort-nils

Fix box collection sorting
This commit is contained in:
Chris Roberts 2024-01-03 18:02:31 -08:00 committed by GitHub
commit dff90bbf74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -299,7 +299,12 @@ module Vagrant
end
# Sort the list to group like providers and properly ordered versions
results.sort_by! do |box_result|
[box_result[0], box_result[2], Gem::Version.new(box_result[1]), box_result[3]]
[
box_result[0],
box_result[2],
Gem::Version.new(box_result[1]),
box_result[3] || :""
]
end
results
end

View File

@ -111,6 +111,17 @@ describe Vagrant::BoxCollection, :skip_windows, :bsdtar do
end.not_to raise_error
end
context "with architectures defined" do
before do
environment.box3("foo-VAGRANTSLASH-bar", "1.0", :virtualbox, architecture: :arm64)
end
it "should sort boxes by name" do
result = subject.all.map(&:first).uniq
expect(result).to eq(["bar", "foo", "foo/bar", "foo:colon"])
end
end
it "should sort boxes by version" do
box_list = subject.all.find_all do |box_info|
box_info[0] == "foo" && box_info[2].to_s == "virtualbox"