Skip to content

Commit deee7ce

Browse files
committed
spec/stream_common_spec: Group write_body_from_file tests
1 parent 807af1b commit deee7ce

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

spec/stream_common_spec.lua

+41-39
Original file line numberDiff line numberDiff line change
@@ -84,46 +84,48 @@ describe("http.stream_common", function()
8484
client:close()
8585
server:close()
8686
end)
87-
it("can write body from temporary file", function()
88-
local server, client = new_pair(1.1)
89-
local cq = cqueues.new()
90-
cq:wrap(function()
91-
local file = io.tmpfile()
92-
assert(file:write("hello world!"))
93-
assert(file:seek("set"))
94-
local stream = client:new_stream()
95-
assert(stream:write_headers(new_request_headers(), false))
96-
assert(stream:write_body_from_file(file))
87+
describe("write_body_from_file", function()
88+
it("works with a temporary file", function()
89+
local server, client = new_pair(1.1)
90+
local cq = cqueues.new()
91+
cq:wrap(function()
92+
local file = io.tmpfile()
93+
assert(file:write("hello world!"))
94+
assert(file:seek("set"))
95+
local stream = client:new_stream()
96+
assert(stream:write_headers(new_request_headers(), false))
97+
assert(stream:write_body_from_file(file))
98+
end)
99+
cq:wrap(function()
100+
local stream = assert(server:get_next_incoming_stream())
101+
assert.same("hello world!", assert(stream:get_body_as_string()))
102+
end)
103+
assert_loop(cq, TEST_TIMEOUT)
104+
assert.truthy(cq:empty())
105+
client:close()
106+
server:close()
97107
end)
98-
cq:wrap(function()
99-
local stream = assert(server:get_next_incoming_stream())
100-
assert.same("hello world!", assert(stream:get_body_as_string()))
108+
it("works using the options form", function()
109+
local server, client = new_pair(1.1)
110+
local cq = cqueues.new()
111+
cq:wrap(function()
112+
local file = io.tmpfile()
113+
assert(file:write("hello world!"))
114+
assert(file:seek("set"))
115+
local stream = client:new_stream()
116+
assert(stream:write_headers(new_request_headers(), false))
117+
assert(stream:write_body_from_file({
118+
file = file;
119+
}))
120+
end)
121+
cq:wrap(function()
122+
local stream = assert(server:get_next_incoming_stream())
123+
assert.same("hello world!", assert(stream:get_body_as_string()))
124+
end)
125+
assert_loop(cq, TEST_TIMEOUT)
126+
assert.truthy(cq:empty())
127+
client:close()
128+
server:close()
101129
end)
102-
assert_loop(cq, TEST_TIMEOUT)
103-
assert.truthy(cq:empty())
104-
client:close()
105-
server:close()
106-
end)
107-
it("can write body from temporary file using options form", function()
108-
local server, client = new_pair(1.1)
109-
local cq = cqueues.new()
110-
cq:wrap(function()
111-
local file = io.tmpfile()
112-
assert(file:write("hello world!"))
113-
assert(file:seek("set"))
114-
local stream = client:new_stream()
115-
assert(stream:write_headers(new_request_headers(), false))
116-
assert(stream:write_body_from_file({
117-
file = file;
118-
}))
119-
end)
120-
cq:wrap(function()
121-
local stream = assert(server:get_next_incoming_stream())
122-
assert.same("hello world!", assert(stream:get_body_as_string()))
123-
end)
124-
assert_loop(cq, TEST_TIMEOUT)
125-
assert.truthy(cq:empty())
126-
client:close()
127-
server:close()
128130
end)
129131
end)

0 commit comments

Comments
 (0)