Fix failing test.
This commit is contained in:
parent
16b2a14c94
commit
9885fbc129
@ -10,9 +10,16 @@ describe CurlDownloadStrategy do
|
|||||||
let(:version) { "1.2.3" }
|
let(:version) { "1.2.3" }
|
||||||
let(:specs) { { user: "download:123456" } }
|
let(:specs) { { user: "download:123456" } }
|
||||||
let(:artifact_domain) { nil }
|
let(:artifact_domain) { nil }
|
||||||
|
let(:headers) do
|
||||||
|
{
|
||||||
|
"accept-ranges" => "bytes",
|
||||||
|
"content-length" => "37182",
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
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
|
end
|
||||||
|
|
||||||
it "parses the opts and sets the corresponding args" do
|
it "parses the opts and sets the corresponding args" do
|
||||||
|
@ -174,21 +174,20 @@ module Utils
|
|||||||
destination.dirname.mkpath
|
destination.dirname.mkpath
|
||||||
|
|
||||||
if try_partial
|
if try_partial
|
||||||
range_stdout = curl_output("--location", "--head", *args, **options).stdout
|
headers = begin
|
||||||
parsed_output = parse_curl_output(range_stdout)
|
parsed_output = curl_headers(*args, **options, wanted_headers: ["accept-ranges"])
|
||||||
|
parsed_output.fetch(:responses).last&.fetch(:headers)
|
||||||
headers = if parsed_output[:responses].present?
|
rescue ErrorDuringExecution
|
||||||
parsed_output[:responses].last[:headers]
|
nil
|
||||||
else
|
|
||||||
{}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Any value for `accept-ranges` other than none indicates that the server supports partial requests.
|
# Any value for `accept-ranges` other than none indicates that the server supports partial requests.
|
||||||
# Its absence indicates no support.
|
# 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 &&
|
if supports_partial &&
|
||||||
destination.exist? &&
|
destination.exist? &&
|
||||||
|
headers&.key?("content-length") &&
|
||||||
destination.size == headers["content-length"].to_i
|
destination.size == headers["content-length"].to_i
|
||||||
return # We've already downloaded all the bytes
|
return # We've already downloaded all the bytes
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user