Fix failing test.

This commit is contained in:
Markus Reiter 2023-05-19 13:58:58 +02:00
parent 16b2a14c94
commit 9885fbc129
No known key found for this signature in database
GPG Key ID: 245293B51702655B
2 changed files with 15 additions and 9 deletions

View File

@ -10,9 +10,16 @@ describe CurlDownloadStrategy do
let(:version) { "1.2.3" }
let(:specs) { { user: "download:123456" } }
let(:artifact_domain) { nil }
let(:headers) do
{
"accept-ranges" => "bytes",
"content-length" => "37182",
}
end
before do
allow(strategy).to receive(:curl_headers).and_return({ responses: [{ headers: {} }] })
allow(strategy).to receive(:curl_headers).with(any_args)
.and_return({ responses: [{ headers: headers }] })
end
it "parses the opts and sets the corresponding args" do

View File

@ -174,21 +174,20 @@ module Utils
destination.dirname.mkpath
if try_partial
range_stdout = curl_output("--location", "--head", *args, **options).stdout
parsed_output = parse_curl_output(range_stdout)
headers = if parsed_output[:responses].present?
parsed_output[:responses].last[:headers]
else
{}
headers = begin
parsed_output = curl_headers(*args, **options, wanted_headers: ["accept-ranges"])
parsed_output.fetch(:responses).last&.fetch(:headers)
rescue ErrorDuringExecution
nil
end
# Any value for `accept-ranges` other than none indicates that the server supports partial requests.
# Its absence indicates no support.
supports_partial = headers.key?("accept-ranges") && headers["accept-ranges"] != "none"
supports_partial = headers&.key?("accept-ranges") && headers["accept-ranges"] != "none"
if supports_partial &&
destination.exist? &&
headers&.key?("content-length") &&
destination.size == headers["content-length"].to_i
return # We've already downloaded all the bytes
end