Skip to content

Commit

Permalink
tests: use debug option to test for non/chunked uploads
Browse files Browse the repository at this point in the history
This combines the functionality from the previous two commits to not
only trigger both chunked and non-chunked uploads, but also test for
that difference by capturing and inspecting the debug events.
  • Loading branch information
StefanKarpinski committed Dec 14, 2021
1 parent 911368d commit 4e0408a
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,25 @@ include("setup.jl")
url = "$server/put"
file = tempname()
write(file, "Hello, world!")
open(file) do io
# without any content-length headers results in a chunked transfer encoding for upload
resp, json = request_json(url, input=io)
@test json["url"] == url
@test json["data"] == read(file, String)
end
open(file) do io
# with content-length headers results in a non-chunked upload
resp, json = request_json(url, input=io, headers=["Content-Length"=>string(filesize(file))])
@test json["url"] == url
@test json["data"] == read(file, String)
len = filesize(file)
for headers in [Pair{String,String}[], ["Content-Length" => "$len"]]
open(file) do io
events = Pair{String,String}[]
debug(type, msg) = push!(events, type => msg)
resp, json = request_json(url, input=io, debug=debug, headers=headers)
@test json["url"] == url
@test json["data"] == read(file, String)
header_out(hdr::String) = any(events) do (type, msg)
type == "HEADER OUT" && hdr in map(lowercase, split(msg, "\r\n"))
end
chunked = header_out("transfer-encoding: chunked")
content_length = header_out("content-length: $len")
if isempty(headers)
@test chunked && !content_length
else
@test !chunked && content_length
end
end
end
rm(file)
end
Expand Down

0 comments on commit 4e0408a

Please sign in to comment.