commit
9ba77a5ed5
|
@ -9,6 +9,10 @@ module Vagrant
|
||||||
# to cURL. cURL is a much more capable and complete download tool than
|
# to cURL. cURL is a much more capable and complete download tool than
|
||||||
# a hand-rolled Ruby library, so we defer to it's expertise.
|
# a hand-rolled Ruby library, so we defer to it's expertise.
|
||||||
class Downloader
|
class Downloader
|
||||||
|
# Custom user agent provided to cURL so that requests to URL shorteners
|
||||||
|
# are properly tracked.
|
||||||
|
USER_AGENT = "Vagrant cURL Downloader"
|
||||||
|
|
||||||
def initialize(source, destination, options=nil)
|
def initialize(source, destination, options=nil)
|
||||||
@logger = Log4r::Logger.new("vagrant::util::downloader")
|
@logger = Log4r::Logger.new("vagrant::util::downloader")
|
||||||
@source = source.to_s
|
@source = source.to_s
|
||||||
|
@ -32,6 +36,7 @@ module Vagrant
|
||||||
"--fail",
|
"--fail",
|
||||||
"--location",
|
"--location",
|
||||||
"--max-redirs", "10",
|
"--max-redirs", "10",
|
||||||
|
"--user-agent", USER_AGENT,
|
||||||
"--output", @destination
|
"--output", @destination
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -21,12 +21,14 @@ describe Vagrant::Util::Downloader do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#download!" do
|
describe "#download!" do
|
||||||
|
let(:curl_options) {
|
||||||
|
["--fail", "--location", "--max-redirs", "10", "--user-agent", described_class::USER_AGENT, "--output", destination, source, {}]
|
||||||
|
}
|
||||||
|
|
||||||
context "with a good exit status" do
|
context "with a good exit status" do
|
||||||
let(:exit_code) { 0 }
|
let(:exit_code) { 0 }
|
||||||
|
|
||||||
it "downloads the file and returns true" do
|
it "downloads the file and returns true" do
|
||||||
curl_options = ["--fail", "--location", "--max-redirs", "10", "--output", destination, source, {}]
|
|
||||||
|
|
||||||
Vagrant::Util::Subprocess.should_receive(:execute).
|
Vagrant::Util::Subprocess.should_receive(:execute).
|
||||||
with("curl", *curl_options).
|
with("curl", *curl_options).
|
||||||
and_return(subprocess_result)
|
and_return(subprocess_result)
|
||||||
|
@ -39,8 +41,6 @@ describe Vagrant::Util::Downloader do
|
||||||
let(:exit_code) { 1 }
|
let(:exit_code) { 1 }
|
||||||
|
|
||||||
it "raises an exception" do
|
it "raises an exception" do
|
||||||
curl_options = ["--fail", "--location", "--max-redirs", "10", "--output", destination, source, {}]
|
|
||||||
|
|
||||||
Vagrant::Util::Subprocess.should_receive(:execute).
|
Vagrant::Util::Subprocess.should_receive(:execute).
|
||||||
with("curl", *curl_options).
|
with("curl", *curl_options).
|
||||||
and_return(subprocess_result)
|
and_return(subprocess_result)
|
||||||
|
|
Loading…
Reference in New Issue