aboutsummaryrefslogtreecommitdiff
path: root/test/httpfixturetest.lua
diff options
context:
space:
mode:
authorThijs Schreijer <thijs@thijsschreijer.nl>2026-08-31 22:08:11 +0200
committerThijs Schreijer <thijs@thijsschreijer.nl>2026-09-01 07:57:09 +0200
commitc5f169ec303a70707bc48fbece9b52cc90a48de0 (patch)
tree3e4bfc24b51bce648f99b072e47707e6399ed0a4 /test/httpfixturetest.lua
parent0a4fa559e44ed3e77f723092feab977539b8aab0 (diff)
downloadluasocket-c5f169ec303a70707bc48fbece9b52cc90a48de0.tar.gz
luasocket-c5f169ec303a70707bc48fbece9b52cc90a48de0.tar.bz2
luasocket-c5f169ec303a70707bc48fbece9b52cc90a48de0.zip
Add CI-runnable HTTP test fixture on the testsrvr/testclnt harness
Drives socket.http.request against fully scripted, controlled raw HTTP responses over a real socket by reusing the existing testsrvr.lua remote-execution server -- no Apache, no Docker, no third-party hosts. Proves the fixture with a plain-GET smoke test, a chunked-transfer- encoding smoke test, and a test asserting a response body delivered across separately-timed writes (the incremental-delivery capability the upcoming SSE tests need). Wires the new test into the CI regression step. Claude-Session: https://claude.ai/code/session_01SW789SftppghLPVXYbWsGi
Diffstat (limited to 'test/httpfixturetest.lua')
-rw-r--r--test/httpfixturetest.lua68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/httpfixturetest.lua b/test/httpfixturetest.lua
new file mode 100644
index 0000000..89dfd90
--- /dev/null
+++ b/test/httpfixturetest.lua
@@ -0,0 +1,68 @@
1-- Smoke tests proving out the httpfixture.lua harness: drive
2-- socket.http.request against fully scripted, controlled raw HTTP
3-- responses over a real socket via the testsrvr.lua remote-execution
4-- server -- no Apache, no Docker, no third-party hosts. Later SSE tests
5-- build on this same fixture for real-socket, incremental-delivery
6-- coverage.
7local http = require("socket.http")
8local fixture = require("httpfixture")
9
10dofile("testsupport.lua")
11
12local url = "http://" .. fixture.host .. ":" .. fixture.port .. "/"
13
14local control, remote = fixture.connect()
15
16io.write("testing plain GET with a known body: ")
17do
18 local body = "hello, luasocket"
19 local response = fixture.response("200 OK", {
20 "Content-Length: " .. #body,
21 "Connection: close",
22 }, body)
23 fixture.accept_and_send(remote, { response })
24
25 local respbody, code = assert(http.request(url .. "get"))
26 assert(respbody == body, "body mismatch: " .. tostring(respbody))
27 assert(code == 200, "status code mismatch: " .. tostring(code))
28end
29print("ok")
30
31io.write("testing chunked-transfer-encoded body: ")
32do
33 local pieces = { "Hello, ", "chunked ", "world!" }
34 local response = fixture.response("200 OK", {
35 "Transfer-Encoding: chunked",
36 "Connection: close",
37 }, fixture.chunked(pieces))
38 fixture.accept_and_send(remote, { response })
39
40 local respbody, code = assert(http.request(url .. "chunked"))
41 assert(respbody == table.concat(pieces), "body mismatch: " .. tostring(respbody))
42 assert(code == 200, "status code mismatch: " .. tostring(code))
43end
44print("ok")
45
46io.write("testing a body delivered across separately-timed writes: ")
47do
48 local part1, part2 = "partial-", "delivery"
49 local body = part1 .. part2
50 local headersblock = fixture.response("200 OK", {
51 "Content-Length: " .. #body,
52 "Connection: close",
53 }, "")
54 fixture.accept_and_send(remote, {
55 headersblock,
56 { part1, delay = 0.2 },
57 part2,
58 })
59
60 local respbody, code = assert(http.request(url .. "slow"))
61 assert(respbody == body, "body mismatch: " .. tostring(respbody))
62 assert(code == 200, "status code mismatch: " .. tostring(code))
63end
64print("ok")
65
66remote("os.exit()")
67
68print("the library passed all tests")