Mercurial > hg > nginx-tests
comparison js.t @ 1778:0979f22e3a5b
Tests: added extended request arguments tests.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Thu, 14 Jul 2022 20:05:07 -0700 |
parents | 410072f42157 |
children | 386748f328b1 |
comparison
equal
deleted
inserted
replaced
1777:410072f42157 | 1778:0979f22e3a5b |
---|---|
39 | 39 |
40 js_set $test_method test.method; | 40 js_set $test_method test.method; |
41 js_set $test_version test.version; | 41 js_set $test_version test.version; |
42 js_set $test_addr test.addr; | 42 js_set $test_addr test.addr; |
43 js_set $test_uri test.uri; | 43 js_set $test_uri test.uri; |
44 js_set $test_arg test.arg; | |
45 js_set $test_iarg test.iarg; | |
46 js_set $test_var test.variable; | 44 js_set $test_var test.variable; |
47 js_set $test_type test.type; | 45 js_set $test_type test.type; |
48 js_set $test_global test.global_obj; | 46 js_set $test_global test.global_obj; |
49 js_set $test_log test.log; | 47 js_set $test_log test.log; |
50 js_set $test_except test.except; | 48 js_set $test_except test.except; |
73 | 71 |
74 location /uri { | 72 location /uri { |
75 return 200 $test_uri; | 73 return 200 $test_uri; |
76 } | 74 } |
77 | 75 |
78 location /arg { | |
79 return 200 $test_arg; | |
80 } | |
81 | |
82 location /iarg { | |
83 return 200 $test_iarg; | |
84 } | |
85 | |
86 location /var { | 76 location /var { |
87 return 200 $test_var; | 77 return 200 $test_var; |
88 } | 78 } |
89 | 79 |
90 location /global { | 80 location /global { |
118 | 108 |
119 location /return_method { | 109 location /return_method { |
120 js_content test.return_method; | 110 js_content test.return_method; |
121 } | 111 } |
122 | 112 |
123 location /arg_keys { | |
124 js_content test.arg_keys; | |
125 } | |
126 | |
127 location /type { | 113 location /type { |
128 js_content test.type; | 114 js_content test.type; |
129 } | 115 } |
130 | 116 |
131 location /log { | 117 location /log { |
167 return 'addr=' + r.remoteAddress; | 153 return 'addr=' + r.remoteAddress; |
168 } | 154 } |
169 | 155 |
170 function uri(r) { | 156 function uri(r) { |
171 return 'uri=' + r.uri; | 157 return 'uri=' + r.uri; |
172 } | |
173 | |
174 function arg(r) { | |
175 return 'arg=' + r.args.foo; | |
176 } | |
177 | |
178 function iarg(r) { | |
179 var s = '', a; | |
180 for (a in r.args) { | |
181 if (a.substr(0, 3) == 'foo') { | |
182 s += r.args[a]; | |
183 } | |
184 } | |
185 return s; | |
186 } | 158 } |
187 | 159 |
188 function variable(r) { | 160 function variable(r) { |
189 return 'variable=' + r.variables.remote_addr; | 161 return 'variable=' + r.variables.remote_addr; |
190 } | 162 } |
230 | 202 |
231 function return_method(r) { | 203 function return_method(r) { |
232 r.return(Number(r.args.c), r.args.t); | 204 r.return(Number(r.args.c), r.args.t); |
233 } | 205 } |
234 | 206 |
235 function arg_keys(r) { | |
236 r.return(200, Object.keys(r.args).sort()); | |
237 } | |
238 | |
239 function type(r) { | 207 function type(r) { |
240 var p = r.args.path.split('.').reduce((a, v) => a[v], r); | 208 var p = r.args.path.split('.').reduce((a, v) => a[v], r); |
241 | 209 |
242 var typ = Buffer.isBuffer(p) ? 'buffer' : (typeof p); | 210 var typ = Buffer.isBuffer(p) ? 'buffer' : (typeof p); |
243 r.return(200, `type: \${typ}`); | 211 r.return(200, `type: \${typ}`); |
258 } | 226 } |
259 | 227 |
260 function content_empty(r) { | 228 function content_empty(r) { |
261 } | 229 } |
262 | 230 |
263 export default {njs:test_njs, method, version, addr, uri, arg, iarg, | 231 export default {njs:test_njs, method, version, addr, uri, |
264 variable, global_obj, status, request_body, | 232 variable, global_obj, status, request_body, |
265 request_body_cache, send, return_method, arg_keys, | 233 request_body_cache, send, return_method, |
266 type, log, except, content_except, content_empty}; | 234 type, log, except, content_except, content_empty}; |
267 | 235 |
268 EOF | 236 EOF |
269 | 237 |
270 $t->try_run('no njs available')->plan(33); | 238 $t->try_run('no njs available')->plan(27); |
271 | 239 |
272 ############################################################################### | 240 ############################################################################### |
273 | 241 |
274 like(http_get('/method'), qr/method=GET/, 'r.method'); | 242 like(http_get('/method'), qr/method=GET/, 'r.method'); |
275 like(http_get('/version'), qr/version=1.0/, 'r.httpVersion'); | 243 like(http_get('/version'), qr/version=1.0/, 'r.httpVersion'); |
276 like(http_get('/addr'), qr/addr=127.0.0.1/, 'r.remoteAddress'); | 244 like(http_get('/addr'), qr/addr=127.0.0.1/, 'r.remoteAddress'); |
277 like(http_get('/uri'), qr/uri=\/uri/, 'r.uri'); | 245 like(http_get('/uri'), qr/uri=\/uri/, 'r.uri'); |
278 like(http_get('/arg?foo=12345'), qr/arg=12345/, 'r.args'); | |
279 like(http_get('/iarg?foo=12345&foo2=bar&nn=22&foo-3=z'), qr/12345barz/, | |
280 'r.args iteration'); | |
281 | |
282 like(http_get('/iarg?foo=123&foo2=&foo3&foo4=456'), qr/123undefined456/, | |
283 'r.args iteration 2'); | |
284 like(http_get('/iarg?foo=123&foo2=&foo3'), qr/123/, 'r.args iteration 3'); | |
285 like(http_get('/iarg?foo=123&foo2='), qr/123/, 'r.args iteration 4'); | |
286 | 246 |
287 like(http_get('/status'), qr/204 No Content/, 'r.status'); | 247 like(http_get('/status'), qr/204 No Content/, 'r.status'); |
288 | 248 |
289 like(http_post('/body'), qr/REQ-BODY/, 'request body'); | 249 like(http_post('/body'), qr/REQ-BODY/, 'request body'); |
290 like(http_post('/in_file'), qr/request body is in a file/, | 250 like(http_post('/in_file'), qr/request body is in a file/, |
301 'return text'); | 261 'return text'); |
302 like(http_get('/return_method?c=301&t=path'), qr/ 301 .*Location: path/s, | 262 like(http_get('/return_method?c=301&t=path'), qr/ 301 .*Location: path/s, |
303 'return redirect'); | 263 'return redirect'); |
304 like(http_get('/return_method?c=404'), qr/404 Not.*html/s, 'return error page'); | 264 like(http_get('/return_method?c=404'), qr/404 Not.*html/s, 'return error page'); |
305 like(http_get('/return_method?c=inv'), qr/ 500 /, 'return invalid'); | 265 like(http_get('/return_method?c=inv'), qr/ 500 /, 'return invalid'); |
306 | |
307 like(http_get('/arg_keys?b=1&c=2&a=5'), qr/a,b,c/m, 'r.args sorted keys'); | |
308 | 266 |
309 TODO: { | 267 TODO: { |
310 local $TODO = 'not yet' | 268 local $TODO = 'not yet' |
311 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.5.0'; | 269 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.5.0'; |
312 | 270 |