diff --git a/spec/stream_common_spec.lua b/spec/stream_common_spec.lua index f8681945..4cc19e3f 100644 --- a/spec/stream_common_spec.lua +++ b/spec/stream_common_spec.lua @@ -84,46 +84,48 @@ describe("http.stream_common", function() client:close() server:close() end) - it("can write body from temporary file", function() - local server, client = new_pair(1.1) - local cq = cqueues.new() - cq:wrap(function() - local file = io.tmpfile() - assert(file:write("hello world!")) - assert(file:seek("set")) - local stream = client:new_stream() - assert(stream:write_headers(new_request_headers(), false)) - assert(stream:write_body_from_file(file)) + describe("write_body_from_file", function() + it("works with a temporary file", function() + local server, client = new_pair(1.1) + local cq = cqueues.new() + cq:wrap(function() + local file = io.tmpfile() + assert(file:write("hello world!")) + assert(file:seek("set")) + local stream = client:new_stream() + assert(stream:write_headers(new_request_headers(), false)) + assert(stream:write_body_from_file(file)) + end) + cq:wrap(function() + local stream = assert(server:get_next_incoming_stream()) + assert.same("hello world!", assert(stream:get_body_as_string())) + end) + assert_loop(cq, TEST_TIMEOUT) + assert.truthy(cq:empty()) + client:close() + server:close() end) - cq:wrap(function() - local stream = assert(server:get_next_incoming_stream()) - assert.same("hello world!", assert(stream:get_body_as_string())) + it("works using the options form", function() + local server, client = new_pair(1.1) + local cq = cqueues.new() + cq:wrap(function() + local file = io.tmpfile() + assert(file:write("hello world!")) + assert(file:seek("set")) + local stream = client:new_stream() + assert(stream:write_headers(new_request_headers(), false)) + assert(stream:write_body_from_file({ + file = file; + })) + end) + cq:wrap(function() + local stream = assert(server:get_next_incoming_stream()) + assert.same("hello world!", assert(stream:get_body_as_string())) + end) + assert_loop(cq, TEST_TIMEOUT) + assert.truthy(cq:empty()) + client:close() + server:close() end) - assert_loop(cq, TEST_TIMEOUT) - assert.truthy(cq:empty()) - client:close() - server:close() - end) - it("can write body from temporary file using options form", function() - local server, client = new_pair(1.1) - local cq = cqueues.new() - cq:wrap(function() - local file = io.tmpfile() - assert(file:write("hello world!")) - assert(file:seek("set")) - local stream = client:new_stream() - assert(stream:write_headers(new_request_headers(), false)) - assert(stream:write_body_from_file({ - file = file; - })) - end) - cq:wrap(function() - local stream = assert(server:get_next_incoming_stream()) - assert.same("hello world!", assert(stream:get_body_as_string())) - end) - assert_loop(cq, TEST_TIMEOUT) - assert.truthy(cq:empty()) - client:close() - server:close() end) end)