From 67c3f866ddf6ac6e206c122083f7fe1e597a75a0 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 25 Apr 2018 13:32:39 -0700 Subject: [PATCH] (#7886) Add tests and simplify code for continuing on 416 --- lib/vagrant/util/downloader.rb | 14 ++++++++++---- test/unit/vagrant/util/downloader_test.rb | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/vagrant/util/downloader.rb b/lib/vagrant/util/downloader.rb index f19d3ffef..285f83b75 100644 --- a/lib/vagrant/util/downloader.rb +++ b/lib/vagrant/util/downloader.rb @@ -292,14 +292,20 @@ module Vagrant # show an error message. if result.exit_code != 0 @logger.warn("Downloader exit code: #{result.exit_code}") - parts = result.stderr.split(/\n*curl:\s+\(\d+\)\s*/, 2) - parts[1] ||= "" - if parts[1].include? "416" + check = result.stderr.match(/\n*curl:\s+\((?\d+)\)\s*(?.*)$/) + if check && check[:code] == "416" # All good actually. 416 means there is no more bytes to download + @logger.warn("Downloader got a 416, but is likely fine. Continuing on...") else + if !check + err_msg = result.stderr + else + err_msg = check[:error] + end + raise Errors::DownloaderError, code: result.exit_code, - message: parts[1].chomp + message: err_msg end end diff --git a/test/unit/vagrant/util/downloader_test.rb b/test/unit/vagrant/util/downloader_test.rb index 772412fbc..b335fe685 100644 --- a/test/unit/vagrant/util/downloader_test.rb +++ b/test/unit/vagrant/util/downloader_test.rb @@ -41,6 +41,20 @@ describe Vagrant::Util::Downloader do context "with a bad exit status" do let(:exit_code) { 1 } + let(:subprocess_result_416) do + double("subprocess_result").tap do |result| + allow(result).to receive(:exit_code).and_return(exit_code) + allow(result).to receive(:stderr).and_return("curl: (416) The download is fine") + end + end + + it "continues on if a 416 was received" do + expect(Vagrant::Util::Subprocess).to receive(:execute). + with("curl", *curl_options). + and_return(subprocess_result_416) + + expect(subject.download!).to be(true) + end it "raises an exception" do expect(Vagrant::Util::Subprocess).to receive(:execute).