From 834e84fa6e7e20b449afb211f58a2d3db4c6665c Mon Sep 17 00:00:00 2001 From: Allison Larson Date: Mon, 24 Feb 2025 15:41:07 -0800 Subject: [PATCH] Include arch constraint when checking global outdated boxes --- plugins/commands/box/command/outdated.rb | 3 +- .../commands/box/command/outdated_test.rb | 101 ++++++++++++++++++ 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/plugins/commands/box/command/outdated.rb b/plugins/commands/box/command/outdated.rb index e7dab0ad4..55c456ced 100644 --- a/plugins/commands/box/command/outdated.rb +++ b/plugins/commands/box/command/outdated.rb @@ -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 diff --git a/test/unit/plugins/commands/box/command/outdated_test.rb b/test/unit/plugins/commands/box/command/outdated_test.rb index 7548bda44..6df34ade4 100644 --- a/test/unit/plugins/commands/box/command/outdated_test.rb +++ b/test/unit/plugins/commands/box/command/outdated_test.rb @@ -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