Skip to content

Commit

Permalink
spec/stream_common_spec: Group write_body_from_file tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daurnimator committed Aug 26, 2018
1 parent 807af1b commit deee7ce
Showing 1 changed file with 41 additions and 39 deletions.
80 changes: 41 additions & 39 deletions spec/stream_common_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit deee7ce

Please # to comment.