Download the box specified by the URL if it doesn't yet exist [closes GH-113]

Thanks a lot to Vitor Pellegrino for much of the work on this.
This commit is contained in:
Mitchell Hashimoto 2010-07-23 22:22:50 -07:00
parent 0e1a304cb8
commit f472dbde44
3 changed files with 15 additions and 1 deletions

View File

@ -15,6 +15,8 @@ module Vagrant
return env.error!(:box_specified_doesnt_exist, :box_name => box_name) if !box_url
env.logger.info "Box #{box_name} not found. Fetching box since URL specified..."
Vagrant::Box.add(env.env, box_name, box_url)
env.env.load_box!
end
@app.call(env)

View File

@ -32,7 +32,7 @@ class Test::Unit::TestCase
config.ssh.private_key_path = '~/foo'
config.vm.box = "foo"
config.vm.box_url = "http://mycompany.com/protected/my_box.box"
config.vm.box_url = nil
config.vm.box_ovf = "box.ovf"
config.vm.base_mac = "42"
config.vm.disk_image_format = 'VMDK'

View File

@ -32,5 +32,17 @@ class CheckBoxVMActionTest < Test::Unit::TestCase
assert @env.error?
assert_equal :box_specified_doesnt_exist, @env.error.first
end
should "attempt to download box and continue if URL specified" do
seq = sequence("seq")
@env.env.config.vm.box_url = "bar"
Vagrant::Box.expects(:find).returns(nil)
Vagrant::Box.expects(:add).with(@env.env, @env["config"].vm.box, @env["config"].vm.box_url).in_sequence(seq)
@env.env.expects(:load_box!).in_sequence(seq)
@app.expects(:call).with(@env).once.in_sequence(seq)
@instance.call(@env)
assert !@env.error?
end
end
end