Skip to content

Commit d53af46

Browse files
authored
Merge pull request #13647 from chrisroberts/box-add-arch
Fix box add action to include architecture
2 parents 87dd75a + cc355dd commit d53af46

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

lib/vagrant/action/builtin/box_add.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def add_from_metadata(url, env, expanded)
292292
# If we have only one provider in the metadata, just use that
293293
# provider.
294294
metadata_provider = metadata_version.provider(
295-
metadata_version.providers.first, architecture)
295+
metadata_version.providers(architecture).first, architecture)
296296
else
297297
providers = metadata_version.providers(architecture).sort
298298

test/unit/vagrant/action/builtin/box_add_test.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,57 @@ def with_web_server(path, **opts)
10331033
subject.call(env)
10341034
end
10351035

1036+
it "adds the latest version of a box with multiple providers and only one provider matching architecture" do
1037+
box_path = iso_env.box2_file(:virtualbox)
1038+
tf = Tempfile.new(["vagrant-box-latest-version", ".json"]).tap do |f|
1039+
# NOTE: The order of the providers here matters. The correct match needs
1040+
# to be last in order to trigger the error this test was written for to
1041+
# catch any regression.
1042+
f.write(
1043+
{
1044+
name: "foo/bar",
1045+
versions: [
1046+
{
1047+
version: "0.5",
1048+
},
1049+
{
1050+
version: "0.7",
1051+
providers: [
1052+
{
1053+
name: "virtualbox",
1054+
url: "/dev/null/invalid.path",
1055+
architecture: "amd64",
1056+
default_architecture: true,
1057+
},
1058+
{
1059+
name: "hyperv",
1060+
url: "#{box_path}",
1061+
architecture: "test-arch",
1062+
default_architecture: true,
1063+
}
1064+
]
1065+
}
1066+
]
1067+
}.to_json
1068+
)
1069+
f.close
1070+
end
1071+
1072+
env[:box_url] = tf.path
1073+
expect(box_collection).to receive(:add).with(any_args) { |path, name, version, opts|
1074+
expect(checksum(path)).to eq(checksum(box_path))
1075+
expect(name).to eq("foo/bar")
1076+
expect(version).to eq("0.7")
1077+
expect(opts[:metadata_url]).to eq("file://#{tf.path}")
1078+
expect(opts[:architecture]).to eq("test-arch")
1079+
true
1080+
}.and_return(box)
1081+
1082+
expect(app).to receive(:call).with(env)
1083+
1084+
subject.call(env)
1085+
end
1086+
10361087
it "adds the latest version of a box with only one provider and unknown architecture set as default" do
10371088
box_path = iso_env.box2_file(:virtualbox)
10381089
tf = Tempfile.new(["vagrant-box-latest-version", ".json"]).tap do |f|

0 commit comments

Comments
 (0)