Fixes #11163: Get latest version for provider

This commit changes the behavior of `vagrant box outdated --global` so
it gets the latest version for the current machine's provider, rather
than the latest version for any provider.
This commit is contained in:
Jeff Bonhag 2019-11-13 12:35:29 -05:00
parent 2ea9323d0b
commit 643a6a5bc6
2 changed files with 138 additions and 1 deletions

View File

@ -73,7 +73,12 @@ module VagrantPlugins
end
current = Gem::Version.new(box.version)
latest = Gem::Version.new(md.versions.last)
provider_latest = md.version(">= #{box.version}", provider: box.provider)
if provider_latest
latest = Gem::Version.new(provider_latest.version)
else
latest = Gem::Version.new(current)
end
if latest <= current
@env.ui.success(I18n.t(
"vagrant.box_up_to_date",

View File

@ -0,0 +1,132 @@
require File.expand_path("../../../../../base", __FILE__)
require Vagrant.source_root.join("plugins/commands/box/command/outdated")
describe VagrantPlugins::CommandBox::Command::Outdated do
include_context "unit"
let(:argv) { [] }
let(:iso_env) do
env = isolated_environment
env.vagrantfile("")
env.create_vagrant_env
end
subject { described_class.new(argv, iso_env) }
let(:action_runner) { double("action_runner") }
before do
allow(iso_env).to receive(:action_runner).and_return(action_runner)
end
context "with global argument" do
let(:argv) { ["--global"] }
it "calls outdated_global" do
expect(subject).to receive(:outdated_global)
subject.execute
end
before do
end
describe ".outdated_global" do
let(:test_iso_env) { isolated_environment }
let(:md) {
md = Vagrant::BoxMetadata.new(StringIO.new(<<-RAW))
{
"name": "foo",
"versions": [
{
"version": "1.0"
},
{
"version": "1.1",
"providers": [
{
"name": "virtualbox",
"url": "bar"
}
]
},
{
"version": "1.2",
"providers": [
{
"name": "vmware",
"url": "baz"
}
]
}
]
}
RAW
}
let(:collection) do
collection = double("collection")
allow(collection).to receive(:all).and_return([box])
allow(collection).to receive(:find).and_return(box)
collection
end
context "when latest version is available for provider" do
let(:box) do
box_dir = test_iso_env.box3("foo", "1.0", :vmware)
box = Vagrant::Box.new(
"foo", :vmware, "1.0", box_dir, metadata_url: "foo")
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" do
let(:box) do
box_dir = test_iso_env.box3("foo", "1.0", :virtualbox)
box = Vagrant::Box.new(
"foo", :virtualbox, "1.0", box_dir, metadata_url: "foo")
allow(box).to receive(:load_metadata).and_return(md)
box
end
it "displays the latest version for that provider" 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 for provider" do
let(:box) do
box_dir = test_iso_env.box3("foo", "1.0", :libvirt)
box = Vagrant::Box.new(
"foo", :libvirt, "1.0", box_dir, metadata_url: "foo")
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.0"))
subject.outdated_global({})
end
end
end
end
end