diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2002-07-08 21:54:28 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2002-07-08 21:54:28 +0000 |
commit | daff3db32ed52aa18dbe1e8c613535fbe0c622c7 (patch) | |
tree | 2e33926020353496960d81d7999486a5a473086e | |
parent | 65dd6185533031421fef4a9fb5f1c919124c86a6 (diff) | |
download | luasocket-daff3db32ed52aa18dbe1e8c613535fbe0c622c7.tar.gz luasocket-daff3db32ed52aa18dbe1e8c613535fbe0c622c7.tar.bz2 luasocket-daff3db32ed52aa18dbe1e8c613535fbe0c622c7.zip |
Using noglobals.lua
Não carrega mais os modulos.
Ajeitados alguns nomes.
-rw-r--r-- | test/httptest.lua | 71 |
1 files changed, 30 insertions, 41 deletions
diff --git a/test/httptest.lua b/test/httptest.lua index 86cb8af..85c8bd8 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
@@ -1,21 +1,14 @@ | |||
1 | -- needs Alias from /home/i/diego/public/html/luasocket/test to | 1 | -- needs Alias from /home/c/diego/tec/luasocket/test to |
2 | -- /luasocket-test | 2 | -- /luasocket-test |
3 | -- needs ScriptAlias from /home/i/diego/public/html/luasocket/test/cgi | 3 | -- needs ScriptAlias from /home/c/diego/tec/luasocket/test/cgi |
4 | -- to /luasocket-test/cgi | 4 | -- to /luasocket-test-cgi |
5 | -- needs AllowOverride AuthConfig on /home/c/diego/tec/luasocket/test/auth | ||
5 | 6 | ||
6 | function mysetglobal (varname, oldvalue, newvalue) | 7 | dofile("noglobals.lua") |
7 | print("changing " .. varname) | ||
8 | %rawset(%globals(), varname, newvalue) | ||
9 | end | ||
10 | function mygetglobal (varname, newvalue) | ||
11 | print("checking " .. varname) | ||
12 | return %rawget(%globals(), varname) | ||
13 | end | ||
14 | settagmethod(tag(nil), "setglobal", mysetglobal) | ||
15 | settagmethod(tag(nil), "getglobal", mygetglobal) | ||
16 | 8 | ||
17 | local similar = function(s1, s2) | 9 | local similar = function(s1, s2) |
18 | return strlower(gsub(s1, "%s", "")) == strlower(gsub(s2, "%s", "")) | 10 | return strlower(gsub(s1 or "", "%s", "")) == |
11 | strlower(gsub(s2 or "", "%s", "")) | ||
19 | end | 12 | end |
20 | 13 | ||
21 | local fail = function(s) | 14 | local fail = function(s) |
@@ -52,36 +45,32 @@ local check_request = function(request, expect, ignore) | |||
52 | print("ok") | 45 | print("ok") |
53 | end | 46 | end |
54 | 47 | ||
55 | local host, request, response, ignore, expect, index, prefix, cgiprefix | 48 | dofile("../src/modules/http.lua") |
56 | 49 | ||
57 | -- load http | 50 | local request, response, ignore, expect, index, prefix, cgiprefix |
58 | assert(dofile("../lua/http.lua")) | ||
59 | assert(dofile("../lua/code.lua")) | ||
60 | assert(dofile("../lua/concat.lua")) | ||
61 | assert(dofile("../lua/url.lua")) | ||
62 | 51 | ||
63 | local t = _time() | 52 | local t = _time() |
64 | 53 | ||
65 | host = host or "localhost" | 54 | HOST = HOST or "localhost" |
66 | prefix = prefix or "/luasocket-test" | 55 | prefix = prefix or "/luasocket-test" |
67 | cgiprefix = cgiprefix or "/luasocket-test-cgi" | 56 | cgiprefix = cgiprefix or "/luasocket-test-cgi" |
68 | index = readfile("index.html") | 57 | index = readfile("index.html") |
69 | 58 | ||
70 | write("testing request uri correctness: ") | 59 | write("testing request uri correctness: ") |
71 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" | 60 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" |
72 | local back = HTTP.get("http://" .. host .. forth) | 61 | local back = HTTP.get("http://" .. HOST .. forth) |
73 | if similar(back, forth) then print("ok") | 62 | if similar(back, forth) then print("ok") |
74 | else fail("failed!") end | 63 | else fail("failed!") end |
75 | 64 | ||
76 | write("testing query string correctness: ") | 65 | write("testing query string correctness: ") |
77 | forth = "this+is+the+query+string" | 66 | forth = "this+is+the+query+string" |
78 | back = HTTP.get("http://" .. host .. cgiprefix .. "/query-string?" .. forth) | 67 | back = HTTP.get("http://" .. HOST .. cgiprefix .. "/query-string?" .. forth) |
79 | if similar(back, forth) then print("ok") | 68 | if similar(back, forth) then print("ok") |
80 | else fail("failed!") end | 69 | else fail("failed!") end |
81 | 70 | ||
82 | write("testing document retrieval: ") | 71 | write("testing document retrieval: ") |
83 | request = { | 72 | request = { |
84 | url = "http://" .. host .. prefix .. "/index.html" | 73 | url = "http://" .. HOST .. prefix .. "/index.html" |
85 | } | 74 | } |
86 | expect = { | 75 | expect = { |
87 | body = index, | 76 | body = index, |
@@ -95,7 +84,7 @@ check_request(request, expect, ignore) | |||
95 | 84 | ||
96 | write("testing HTTP redirection: ") | 85 | write("testing HTTP redirection: ") |
97 | request = { | 86 | request = { |
98 | url = "http://" .. host .. prefix | 87 | url = "http://" .. HOST .. prefix |
99 | } | 88 | } |
100 | expect = { | 89 | expect = { |
101 | body = index, | 90 | body = index, |
@@ -110,7 +99,7 @@ check_request(request, expect, ignore) | |||
110 | 99 | ||
111 | write("testing automatic auth failure: ") | 100 | write("testing automatic auth failure: ") |
112 | request = { | 101 | request = { |
113 | url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html" | 102 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html" |
114 | } | 103 | } |
115 | expect = { | 104 | expect = { |
116 | code = 401 | 105 | code = 401 |
@@ -124,7 +113,7 @@ check_request(request, expect, ignore) | |||
124 | 113 | ||
125 | write("testing HTTP redirection failure: ") | 114 | write("testing HTTP redirection failure: ") |
126 | request = { | 115 | request = { |
127 | url = "http://" .. host .. prefix, | 116 | url = "http://" .. HOST .. prefix, |
128 | stay = 1 | 117 | stay = 1 |
129 | } | 118 | } |
130 | expect = { | 119 | expect = { |
@@ -150,7 +139,7 @@ check_request(request, expect, ignore) | |||
150 | 139 | ||
151 | write("testing invalid url: ") | 140 | write("testing invalid url: ") |
152 | request = { | 141 | request = { |
153 | url = host .. prefix | 142 | url = HOST .. prefix |
154 | } | 143 | } |
155 | local c, e = connect("", 80) | 144 | local c, e = connect("", 80) |
156 | expect = { | 145 | expect = { |
@@ -161,7 +150,7 @@ check_request(request, expect, ignore) | |||
161 | 150 | ||
162 | write("testing document not found: ") | 151 | write("testing document not found: ") |
163 | request = { | 152 | request = { |
164 | url = "http://" .. host .. "/wrongdocument.html" | 153 | url = "http://" .. HOST .. "/wrongdocument.html" |
165 | } | 154 | } |
166 | expect = { | 155 | expect = { |
167 | code = 404 | 156 | code = 404 |
@@ -175,7 +164,7 @@ check_request(request, expect, ignore) | |||
175 | 164 | ||
176 | write("testing auth failure: ") | 165 | write("testing auth failure: ") |
177 | request = { | 166 | request = { |
178 | url = "http://" .. host .. prefix .. "/auth/index.html" | 167 | url = "http://" .. HOST .. prefix .. "/auth/index.html" |
179 | } | 168 | } |
180 | expect = { | 169 | expect = { |
181 | code = 401 | 170 | code = 401 |
@@ -189,7 +178,7 @@ check_request(request, expect, ignore) | |||
189 | 178 | ||
190 | write("testing manual basic auth: ") | 179 | write("testing manual basic auth: ") |
191 | request = { | 180 | request = { |
192 | url = "http://" .. host .. prefix .. "/auth/index.html", | 181 | url = "http://" .. HOST .. prefix .. "/auth/index.html", |
193 | headers = { | 182 | headers = { |
194 | authorization = "Basic " .. Code.base64("luasocket:password") | 183 | authorization = "Basic " .. Code.base64("luasocket:password") |
195 | } | 184 | } |
@@ -206,7 +195,7 @@ check_request(request, expect, ignore) | |||
206 | 195 | ||
207 | write("testing automatic basic auth: ") | 196 | write("testing automatic basic auth: ") |
208 | request = { | 197 | request = { |
209 | url = "http://luasocket:password@" .. host .. prefix .. "/auth/index.html" | 198 | url = "http://luasocket:password@" .. HOST .. prefix .. "/auth/index.html" |
210 | } | 199 | } |
211 | expect = { | 200 | expect = { |
212 | code = 200, | 201 | code = 200, |
@@ -220,7 +209,7 @@ check_request(request, expect, ignore) | |||
220 | 209 | ||
221 | write("testing auth info overriding: ") | 210 | write("testing auth info overriding: ") |
222 | request = { | 211 | request = { |
223 | url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html", | 212 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html", |
224 | user = "luasocket", | 213 | user = "luasocket", |
225 | password = "password" | 214 | password = "password" |
226 | } | 215 | } |
@@ -236,7 +225,7 @@ check_request(request, expect, ignore) | |||
236 | 225 | ||
237 | write("testing cgi output retrieval (probably chunked...): ") | 226 | write("testing cgi output retrieval (probably chunked...): ") |
238 | request = { | 227 | request = { |
239 | url = "http://" .. host .. cgiprefix .. "/cat-index-html" | 228 | url = "http://" .. HOST .. cgiprefix .. "/cat-index-html" |
240 | } | 229 | } |
241 | expect = { | 230 | expect = { |
242 | body = index, | 231 | body = index, |
@@ -250,7 +239,7 @@ check_request(request, expect, ignore) | |||
250 | 239 | ||
251 | write("testing redirect loop: ") | 240 | write("testing redirect loop: ") |
252 | request = { | 241 | request = { |
253 | url = "http://" .. host .. cgiprefix .. "/redirect-loop" | 242 | url = "http://" .. HOST .. cgiprefix .. "/redirect-loop" |
254 | } | 243 | } |
255 | expect = { | 244 | expect = { |
256 | code = 302 | 245 | code = 302 |
@@ -264,7 +253,7 @@ check_request(request, expect, ignore) | |||
264 | 253 | ||
265 | write("testing post method: ") | 254 | write("testing post method: ") |
266 | request = { | 255 | request = { |
267 | url = "http://" .. host .. cgiprefix .. "/cat", | 256 | url = "http://" .. HOST .. cgiprefix .. "/cat", |
268 | method = "POST", | 257 | method = "POST", |
269 | body = index | 258 | body = index |
270 | } | 259 | } |
@@ -280,7 +269,7 @@ check_request(request, expect, ignore) | |||
280 | 269 | ||
281 | write("testing wrong scheme: ") | 270 | write("testing wrong scheme: ") |
282 | request = { | 271 | request = { |
283 | url = "wrong://" .. host .. cgiprefix .. "/cat", | 272 | url = "wrong://" .. HOST .. cgiprefix .. "/cat", |
284 | method = "GET" | 273 | method = "GET" |
285 | } | 274 | } |
286 | expect = { | 275 | expect = { |
@@ -292,24 +281,24 @@ check_request(request, expect, ignore) | |||
292 | 281 | ||
293 | local body | 282 | local body |
294 | write("testing simple get function: ") | 283 | write("testing simple get function: ") |
295 | body = HTTP.get("http://" .. host .. prefix .. "/index.html") | 284 | body = HTTP.get("http://" .. HOST .. prefix .. "/index.html") |
296 | check(body == index) | 285 | check(body == index) |
297 | 286 | ||
298 | write("testing simple get function with table args: ") | 287 | write("testing simple get function with table args: ") |
299 | body = HTTP.get { | 288 | body = HTTP.get { |
300 | url = "http://really:wrong@" .. host .. prefix .. "/auth/index.html", | 289 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html", |
301 | user = "luasocket", | 290 | user = "luasocket", |
302 | password = "password" | 291 | password = "password" |
303 | } | 292 | } |
304 | check(body == index) | 293 | check(body == index) |
305 | 294 | ||
306 | write("testing simple post function: ") | 295 | write("testing simple post function: ") |
307 | body = HTTP.post("http://" .. host .. cgiprefix .. "/cat", index) | 296 | body = HTTP.post("http://" .. HOST .. cgiprefix .. "/cat", index) |
308 | check(body == index) | 297 | check(body == index) |
309 | 298 | ||
310 | write("testing simple post function with table args: ") | 299 | write("testing simple post function with table args: ") |
311 | body = HTTP.post { | 300 | body = HTTP.post { |
312 | url = "http://" .. host .. cgiprefix .. "/cat", | 301 | url = "http://" .. HOST .. cgiprefix .. "/cat", |
313 | body = index | 302 | body = index |
314 | } | 303 | } |
315 | check(body == index) | 304 | check(body == index) |