core: shorthand box adds wor

This commit is contained in:
Mitchell Hashimoto 2014-01-23 22:37:13 -08:00
parent f9fe025d10
commit 5aba445cac
2 changed files with 55 additions and 1 deletions

View File

@ -23,6 +23,15 @@ module Vagrant
@download_interrupted = false @download_interrupted = false
url = env[:box_url] url = env[:box_url]
# If we received a shorthand URL ("mitchellh/precise64"),
# then expand it properly.
uri = URI.parse(url)
if !uri.scheme && !File.file?(url)
url = "#{Vagrant.server_url}/#{url}"
env[:box_url] = url
end
if metadata_url?(url, env) if metadata_url?(url, env)
add_from_metadata(env) add_from_metadata(env)
else else

View File

@ -171,7 +171,6 @@ describe Vagrant::Action::Builtin::BoxAdd do
f.close f.close
end end
md_path = Pathname.new(tf.path) md_path = Pathname.new(tf.path)
with_web_server(md_path) do |port| with_web_server(md_path) do |port|
env[:box_url] = "http://127.0.0.1:#{port}/#{md_path.basename}" env[:box_url] = "http://127.0.0.1:#{port}/#{md_path.basename}"
@ -189,6 +188,52 @@ describe Vagrant::Action::Builtin::BoxAdd do
end end
end end
it "adds from shorthand path" do
box_path = iso_env.box2_file(:virtualbox)
td = Pathname.new(Dir.mktmpdir)
tf = td.join("mitchellh", "precise64.json")
tf.dirname.mkpath
tf.open("w") do |f|
f.write(<<-RAW)
{
"name": "mitchellh/precise64",
"versions": [
{
"version": "0.5"
},
{
"version": "0.7",
"providers": [
{
"name": "virtualbox",
"url": "#{box_path}"
}
]
}
]
}
RAW
end
with_web_server(tf.dirname) do |port|
env[:box_url] = "mitchellh/precise64.json"
box_collection.should_receive(:add).with do |path, name, version|
expect(name).to eq("mitchellh/precise64")
expect(version).to eq("0.7")
expect(checksum(path)).to eq(checksum(box_path))
true
end.and_return(box)
app.should_receive(:call).with(env)
url = "http://127.0.0.1:#{port}"
with_temp_env("VAGRANT_SERVER_URL" => url) do
subject.call(env)
end
end
end
it "adds the latest version of a box with only one provider" do it "adds the latest version of a box with only one provider" do
box_path = iso_env.box2_file(:virtualbox) box_path = iso_env.box2_file(:virtualbox)
tf = Tempfile.new("vagrant").tap do |f| tf = Tempfile.new("vagrant").tap do |f|