File box downloader gives a nice error message if the file doesn't exist.
This commit is contained in:
parent
132aa05f94
commit
ef5e73e950
|
@ -26,6 +26,9 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
raise ActionException.new("Unknown URI type for box download.") unless @downloader
|
raise ActionException.new("Unknown URI type for box download.") unless @downloader
|
||||||
|
|
||||||
|
# Prepare the downloader
|
||||||
|
@downloader.prepare(@runner.uri)
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute!
|
def execute!
|
||||||
|
|
|
@ -5,6 +5,9 @@ module Vagrant
|
||||||
class Base
|
class Base
|
||||||
include Vagrant::Util
|
include Vagrant::Util
|
||||||
|
|
||||||
|
# Called prior to execution so any error checks can be done
|
||||||
|
def prepare(source_url); end
|
||||||
|
|
||||||
# Downloads the source file to the destination file. It is up to
|
# Downloads the source file to the destination file. It is up to
|
||||||
# implementors of this class to handle the logic.
|
# implementors of this class to handle the logic.
|
||||||
def download!(source_url, destination_file); end
|
def download!(source_url, destination_file); end
|
||||||
|
|
|
@ -3,6 +3,16 @@ module Vagrant
|
||||||
# "Downloads" a file to a temporary file. Basically, this downloader
|
# "Downloads" a file to a temporary file. Basically, this downloader
|
||||||
# simply does a file copy.
|
# simply does a file copy.
|
||||||
class File < Base
|
class File < Base
|
||||||
|
def prepare(source_url)
|
||||||
|
if !::File.file?(source_url)
|
||||||
|
raise Actions::ActionException.new(<<-msg)
|
||||||
|
The given box does not exist on the file system:
|
||||||
|
|
||||||
|
#{source_url}
|
||||||
|
msg
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def download!(source_url, destination_file)
|
def download!(source_url, destination_file)
|
||||||
FileUtils.cp(source_url, destination_file.path)
|
FileUtils.cp(source_url, destination_file.path)
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,6 +16,10 @@ class DownloadBoxActionTest < Test::Unit::TestCase
|
||||||
@uri = mock("uri")
|
@uri = mock("uri")
|
||||||
@uri.stubs(:is_a?).returns(false)
|
@uri.stubs(:is_a?).returns(false)
|
||||||
URI.stubs(:parse).returns(@uri)
|
URI.stubs(:parse).returns(@uri)
|
||||||
|
|
||||||
|
@downloader = mock("downloader")
|
||||||
|
Vagrant::Downloaders::File.any_instance.stubs(:prepare)
|
||||||
|
Vagrant::Downloaders::HTTP.any_instance.stubs(:prepare)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "raise an exception if no URI type is matched" do
|
should "raise an exception if no URI type is matched" do
|
||||||
|
@ -25,6 +29,13 @@ class DownloadBoxActionTest < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "call #prepare on the downloader" do
|
||||||
|
@downloader.expects(:prepare).with(@runner.uri).once
|
||||||
|
Vagrant::Downloaders::File.expects(:new).returns(@downloader)
|
||||||
|
@uri.stubs(:is_a?).with(URI::Generic).returns(true)
|
||||||
|
@action.prepare
|
||||||
|
end
|
||||||
|
|
||||||
should "set the downloader to file if URI is generic" do
|
should "set the downloader to file if URI is generic" do
|
||||||
@uri.stubs(:is_a?).with(URI::Generic).returns(true)
|
@uri.stubs(:is_a?).with(URI::Generic).returns(true)
|
||||||
@action.prepare
|
@action.prepare
|
||||||
|
|
|
@ -11,6 +11,13 @@ class BaseDownloaderTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
should "implement prepare which does nothing" do
|
should "implement prepare which does nothing" do
|
||||||
|
assert_nothing_raised do
|
||||||
|
assert @base.respond_to?(:prepare)
|
||||||
|
@base.prepare("source")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "implement download! which does nothing" do
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
assert @base.respond_to?(:download!)
|
assert @base.respond_to?(:download!)
|
||||||
@base.download!("source", "destination")
|
@base.download!("source", "destination")
|
||||||
|
|
|
@ -6,6 +6,15 @@ class FileDownloaderTest < Test::Unit::TestCase
|
||||||
@uri = "foo.box"
|
@uri = "foo.box"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "preparing" do
|
||||||
|
should "raise an exception if the file does not exist" do
|
||||||
|
File.expects(:file?).with(@uri).returns(false)
|
||||||
|
assert_raises(Vagrant::Actions::ActionException) {
|
||||||
|
@downloader.prepare(@uri)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "downloading" do
|
context "downloading" do
|
||||||
should "cp the file" do
|
should "cp the file" do
|
||||||
path = '/path'
|
path = '/path'
|
||||||
|
|
Loading…
Reference in New Issue