From f472dbde44449a66ea69222d82594113de8bf401 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 23 Jul 2010 22:22:50 -0700 Subject: [PATCH] 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. --- lib/vagrant/action/vm/check_box.rb | 2 ++ test/test_helper.rb | 2 +- test/vagrant/action/vm/check_box_test.rb | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/action/vm/check_box.rb b/lib/vagrant/action/vm/check_box.rb index 2e04b17f0..cc6e9d291 100644 --- a/lib/vagrant/action/vm/check_box.rb +++ b/lib/vagrant/action/vm/check_box.rb @@ -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) diff --git a/test/test_helper.rb b/test/test_helper.rb index b40857375..386b544da 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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' diff --git a/test/vagrant/action/vm/check_box_test.rb b/test/vagrant/action/vm/check_box_test.rb index 6b8431cde..4d6f0b685 100644 --- a/test/vagrant/action/vm/check_box_test.rb +++ b/test/vagrant/action/vm/check_box_test.rb @@ -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