Skip to content

Commit 3db6e5e

Browse files
committed
Minor fix to the tests.
1 parent 795a5c4 commit 3db6e5e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

example/test.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@ local function urlencode(list)
2121
return table.concat(result, "&")
2222
end
2323

24+
local function checkcode(code, expected)
25+
if code ~= expected then
26+
error("expected code "..expected..", got "..tostring(code))
27+
end
28+
end
29+
2430
math.randomseed(os.time())
2531

2632
-- Tests function
2733

2834
local function test_download_json()
2935
local code, response = https.request("https://raw.githubusercontent.com/rxi/json.lua/master/json.lua")
30-
assert(code == 200, "expected code 200, got "..code)
36+
checkcode(code, 200)
3137
json = assert(loadstring(response, "=json.lua"))()
3238
end
3339

@@ -45,7 +51,7 @@ local function test_custom_header()
4551
[headerName] = tostring(random)
4652
}
4753
})
48-
assert(code == 200, "expected code 200, got "..code)
54+
checkcode(code, 200)
4955
local root = json.decode(response)
5056

5157
-- Headers are case-insensitive
@@ -77,7 +83,7 @@ local function test_send(method, kind)
7783
method = method
7884
})
7985

80-
assert(code == 200, "expected code 200, got "..code)
86+
checkcode(code, 200)
8187
local root = json.decode(response)
8288

8389
for k, v in pairs(data) do
@@ -89,6 +95,7 @@ end
8995
-- Tests call
9096
print("test downloading json library") test_download_json()
9197
print("test custom header") test_custom_header()
98+
print("test HEAD") test_head()
9299

93100
for _, method in ipairs({"POST", "PUT", "PATCH", "DELETE"}) do
94101
for _, kind in ipairs({"form", "json"}) do

0 commit comments

Comments
 (0)