Include arch constraint when checking global outdated boxes

This commit is contained in:
Allison Larson 2025-02-24 15:41:07 -08:00
parent a1ceec1d40
commit 834e84fa6e
2 changed files with 102 additions and 2 deletions

View file

@ -57,7 +57,6 @@ module VagrantPlugins
end
def outdated_global(download_options)
boxes = {}
@env.boxes.all.reverse.each do |name, version, provider|
box = @env.boxes.find(name, provider, version)
if !box.metadata_url
@ -81,7 +80,7 @@ module VagrantPlugins
end
current = Gem::Version.new(box.version)
box_versions = md.versions(provider: box.provider)
box_versions = md.versions(provider: box.provider, architecture: box.architecture)
if box_versions.empty?
latest_box_version = box_versions.last.to_i

View file

@ -138,6 +138,107 @@ describe VagrantPlugins::CommandBox::Command::Outdated do
subject.outdated_global({})
end
end
context "with architectures" do
let(:md) {
md = Vagrant::BoxMetadata.new(StringIO.new(<<-RAW))
{
"name": "foo",
"versions": [
{
"version": "1.0"
},
{
"version": "1.1",
"providers": [
{
"name": "vmware",
"architecture": "amd64",
"url": "bar"
},
{
"name": "virtualbox",
"architecture": "unknown",
"url": "foo"
}
]
},
{
"version": "1.2",
"providers": [
{
"name": "vmware",
"architecture": "arm64",
"url": "baz"
},
{
"name": "virtualbox",
"architecture": "unknown",
"url": "bat"
}
]
}
]
}
RAW
}
context "when latest version is available for provider with unknown architecture" do
let(:box) do
box_dir = test_iso_env.box3("foo", "1.0", :virtualbox, architecture: "arm64")
box = Vagrant::Box.new(
"foo", :virtualbox, "1.0", box_dir, metadata_url: "foo", architecture: "arm64")
allow(box).to receive(:load_metadata).and_return(md)
box
end
it "displays the latest version" do
allow(iso_env).to receive(:boxes).and_return(collection)
expect(I18n).to receive(:t).with(/box_outdated$/, hash_including(latest: "1.2"))
subject.outdated_global({})
end
end
context "when latest version isn't available for provider with explicit architecture" do
let(:box) do
box_dir = test_iso_env.box3("foo", "1.0", :vmware, architecture: "amd64")
box = Vagrant::Box.new(
"foo", :vmware, "1.0", box_dir, metadata_url: "foo", architecture: "amd64")
allow(box).to receive(:load_metadata).and_return(md)
box
end
it "displays the latest version" do
allow(iso_env).to receive(:boxes).and_return(collection)
expect(I18n).to receive(:t).with(/box_outdated$/, hash_including(latest: "1.1"))
subject.outdated_global({})
end
end
context "when no versions are available provider with explicit architecture" do
let(:box) do
box_dir = test_iso_env.box3("foo", "1.1", :vmware)
box = Vagrant::Box.new(
"foo", :vmware, "1.1", box_dir, metadata_url: "foo", architecture: "amd64")
allow(box).to receive(:load_metadata).and_return(md)
box
end
it "displays up to date message" do
allow(iso_env).to receive(:boxes).and_return(collection)
expect(I18n).to receive(:t).with(/box_up_to_date$/, hash_including(version: "1.1"))
subject.outdated_global({})
end
end
end
end
end
end