@@ -21,13 +21,19 @@ local function urlencode(list)
21
21
return table.concat (result , " &" )
22
22
end
23
23
24
+ local function checkcode (code , expected )
25
+ if code ~= expected then
26
+ error (" expected code " .. expected .. " , got " .. tostring (code ))
27
+ end
28
+ end
29
+
24
30
math.randomseed (os.time ())
25
31
26
32
-- Tests function
27
33
28
34
local function test_download_json ()
29
35
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 )
31
37
json = assert (loadstring (response , " =json.lua" ))()
32
38
end
33
39
@@ -45,7 +51,7 @@ local function test_custom_header()
45
51
[headerName ] = tostring (random )
46
52
}
47
53
})
48
- assert (code == 200 , " expected code 200, got " .. code )
54
+ checkcode (code , 200 )
49
55
local root = json .decode (response )
50
56
51
57
-- Headers are case-insensitive
@@ -77,7 +83,7 @@ local function test_send(method, kind)
77
83
method = method
78
84
})
79
85
80
- assert (code == 200 , " expected code 200, got " .. code )
86
+ checkcode (code , 200 )
81
87
local root = json .decode (response )
82
88
83
89
for k , v in pairs (data ) do
89
95
-- Tests call
90
96
print (" test downloading json library" ) test_download_json ()
91
97
print (" test custom header" ) test_custom_header ()
98
+ print (" test HEAD" ) test_head ()
92
99
93
100
for _ , method in ipairs ({" POST" , " PUT" , " PATCH" , " DELETE" }) do
94
101
for _ , kind in ipairs ({" form" , " json" }) do
0 commit comments