Box downloading uses box environment key

This commit is contained in:
Mitchell Hashimoto 2010-07-07 23:23:19 -07:00
parent f6a53ddff0
commit 6e93406069
2 changed files with 10 additions and 9 deletions

View File

@ -29,9 +29,9 @@ module Vagrant
def instantiate_downloader def instantiate_downloader
@env["download.classes"].each do |klass| @env["download.classes"].each do |klass|
if klass.match?(@env["download.uri"]) if klass.match?(@env["box"].uri)
@env.logger.info "Downloading with #{klass}..." @env.logger.info "Downloading with #{klass}..."
@downloader = klass.new(@env["download.uri"]) @downloader = klass.new(@env["box"].uri)
end end
end end
@ -40,7 +40,7 @@ module Vagrant
return false return false
end end
@downloader.prepare(@env["download.uri"]) @downloader.prepare(@env["box"].uri)
true true
end end
@ -71,7 +71,7 @@ module Vagrant
def download_to(f) def download_to(f)
@env.logger.info "Copying box to temporary location..." @env.logger.info "Copying box to temporary location..."
@downloader.download!(@env["download.uri"], f) @downloader.download!(@env["box"].uri, f)
end end
end end
end end

View File

@ -7,6 +7,8 @@ class DownloadBoxActionTest < Test::Unit::TestCase
@vm = mock("vm") @vm = mock("vm")
@env["vm"] = @vm @env["vm"] = @vm
@env["box"] = Vagrant::Box.new(mock_environment, "foo")
@env["box"].uri = "http://google.com"
@internal_vm = mock("internal") @internal_vm = mock("internal")
@vm.stubs(:vm).returns(@internal_vm) @vm.stubs(:vm).returns(@internal_vm)
@ -22,7 +24,6 @@ class DownloadBoxActionTest < Test::Unit::TestCase
context "with an instance" do context "with an instance" do
setup do setup do
@instance = @klass.new(@app, @env) @instance = @klass.new(@app, @env)
@env["download.uri"] = "http://google.com"
end end
context "calling" do context "calling" do
@ -48,13 +49,13 @@ class DownloadBoxActionTest < Test::Unit::TestCase
context "instantiating downloader" do context "instantiating downloader" do
should "instantiate the proper class" do should "instantiate the proper class" do
instance = mock("instance") instance = mock("instance")
Vagrant::Downloaders::HTTP.expects(:new).with(@env["download.uri"]).returns(instance) Vagrant::Downloaders::HTTP.expects(:new).with(@env["box"].uri).returns(instance)
instance.expects(:prepare).with(@env["download.uri"]).once instance.expects(:prepare).with(@env["box"].uri).once
assert @instance.instantiate_downloader assert @instance.instantiate_downloader
end end
should "error environment if URI is invalid for any downloaders" do should "error environment if URI is invalid for any downloaders" do
@env["download.uri"] = "foobar" @env["box"].uri = "foobar"
assert !@instance.instantiate_downloader assert !@instance.instantiate_downloader
assert @env.error? assert @env.error?
assert_equal :box_download_unknown_type, @env.error.first assert_equal :box_download_unknown_type, @env.error.first
@ -131,7 +132,7 @@ class DownloadBoxActionTest < Test::Unit::TestCase
should "call download! on the download with the URI and tempfile" do should "call download! on the download with the URI and tempfile" do
tempfile = "foo" tempfile = "foo"
@downloader.expects(:download!).with(@env["download.uri"], tempfile) @downloader.expects(:download!).with(@env["box"].uri, tempfile)
@instance.download_to(tempfile) @instance.download_to(tempfile)
end end
end end