From 4e0408a69f34e3c6a1948bb6b49296b4d87d026a Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Tue, 14 Dec 2021 16:45:31 -0500 Subject: [PATCH] tests: use debug option to test for non/chunked uploads 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. --- test/runtests.jl | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 3ad4864..406058d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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