Mercurial > hg > nginx-tests
comparison js.t @ 1625:a140cab489e8
Tests: added js buffer tests.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Wed, 25 Nov 2020 12:25:24 +0000 |
parents | bc0990ea2e5b |
children | a35445ae8de7 |
comparison
equal
deleted
inserted
replaced
1624:81fd6615358e | 1625:a140cab489e8 |
---|---|
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; | 44 js_set $test_arg test_arg; |
45 js_set $test_iarg test_iarg; | 45 js_set $test_iarg test_iarg; |
46 js_set $test_var test_var; | 46 js_set $test_var test_var; |
47 js_set $test_type test_type; | |
47 js_set $test_global test_global; | 48 js_set $test_global test_global; |
48 js_set $test_log test_log; | 49 js_set $test_log test_log; |
49 js_set $test_except test_except; | 50 js_set $test_except test_except; |
50 | 51 |
51 js_include test.js; | 52 js_include test.js; |
105 | 106 |
106 location /request_body { | 107 location /request_body { |
107 js_content request_body; | 108 js_content request_body; |
108 } | 109 } |
109 | 110 |
111 location /request_body_cache { | |
112 js_content request_body_cache; | |
113 } | |
114 | |
110 location /send { | 115 location /send { |
111 js_content send; | 116 js_content send; |
112 } | 117 } |
113 | 118 |
114 location /return_method { | 119 location /return_method { |
115 js_content return_method; | 120 js_content return_method; |
116 } | 121 } |
117 | 122 |
118 location /arg_keys { | 123 location /arg_keys { |
119 js_content arg_keys; | 124 js_content arg_keys; |
125 } | |
126 | |
127 location /type { | |
128 js_content test_type; | |
120 } | 129 } |
121 | 130 |
122 location /log { | 131 location /log { |
123 return 200 $test_log; | 132 return 200 $test_log; |
124 } | 133 } |
196 r.return(200, body); | 205 r.return(200, body); |
197 | 206 |
198 } catch (e) { | 207 } catch (e) { |
199 r.return(500, e.message); | 208 r.return(500, e.message); |
200 } | 209 } |
210 } | |
211 | |
212 function request_body_cache(r) { | |
213 function t(v) {return Buffer.isBuffer(v) ? 'buffer' : (typeof v);} | |
214 r.return(200, | |
215 `requestBody:\${t(r.requestBody)} reqBody:\${t(r.reqBody)}`); | |
201 } | 216 } |
202 | 217 |
203 function send(r) { | 218 function send(r) { |
204 var a, s; | 219 var a, s; |
205 r.status = 200; | 220 r.status = 200; |
219 | 234 |
220 function arg_keys(r) { | 235 function arg_keys(r) { |
221 r.return(200, Object.keys(r.args).sort()); | 236 r.return(200, Object.keys(r.args).sort()); |
222 } | 237 } |
223 | 238 |
239 function test_type(r) { | |
240 var p = r.args.path.split('.').reduce((a, v) => a[v], r); | |
241 | |
242 var type = Buffer.isBuffer(p) ? 'buffer' : (typeof p); | |
243 r.return(200, `type: \${type}`); | |
244 } | |
245 | |
224 function test_log(r) { | 246 function test_log(r) { |
225 r.log('SEE-LOG'); | 247 r.log('SEE-LOG'); |
226 } | 248 } |
227 | 249 |
228 function test_except(r) { | 250 function test_except(r) { |
238 function content_empty(r) { | 260 function content_empty(r) { |
239 } | 261 } |
240 | 262 |
241 EOF | 263 EOF |
242 | 264 |
243 $t->try_run('no njs available')->plan(27); | 265 $t->try_run('no njs available')->plan(32); |
244 | 266 |
245 ############################################################################### | 267 ############################################################################### |
246 | 268 |
247 like(http_get('/method'), qr/method=GET/, 'r.method'); | 269 like(http_get('/method'), qr/method=GET/, 'r.method'); |
248 like(http_get('/version'), qr/version=1.0/, 'r.httpVersion'); | 270 like(http_get('/version'), qr/version=1.0/, 'r.httpVersion'); |
276 'return redirect'); | 298 'return redirect'); |
277 like(http_get('/return_method?c=404'), qr/404 Not.*html/s, 'return error page'); | 299 like(http_get('/return_method?c=404'), qr/404 Not.*html/s, 'return error page'); |
278 like(http_get('/return_method?c=inv'), qr/ 500 /, 'return invalid'); | 300 like(http_get('/return_method?c=inv'), qr/ 500 /, 'return invalid'); |
279 | 301 |
280 like(http_get('/arg_keys?b=1&c=2&a=5'), qr/a,b,c/m, 'r.args sorted keys'); | 302 like(http_get('/arg_keys?b=1&c=2&a=5'), qr/a,b,c/m, 'r.args sorted keys'); |
303 | |
304 TODO: { | |
305 local $TODO = 'not yet' | |
306 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.5.0'; | |
307 | |
308 like(http_get('/type?path=variables.host'), qr/200 OK.*type: string$/s, | |
309 'variables type'); | |
310 like(http_get('/type?path=vars.host'), qr/200 OK.*type: buffer$/s, | |
311 'vars type'); | |
312 | |
313 like(http_post('/type?path=requestBody'), qr/200 OK.*type: string$/s, | |
314 'requestBody type'); | |
315 like(http_post('/type?path=reqBody'), qr/200 OK.*type: buffer$/s, | |
316 'reqBody type'); | |
317 like(http_post('/request_body_cache'), qr/requestBody:string reqBody:buffer$/s, | |
318 'reqBody type'); | |
319 | |
320 } | |
281 | 321 |
282 like(http_get('/var'), qr/variable=127.0.0.1/, 'r.variables'); | 322 like(http_get('/var'), qr/variable=127.0.0.1/, 'r.variables'); |
283 like(http_get('/global'), qr/global=njs/, 'global code'); | 323 like(http_get('/global'), qr/global=njs/, 'global code'); |
284 like(http_get('/log'), qr/200 OK/, 'r.log'); | 324 like(http_get('/log'), qr/200 OK/, 'r.log'); |
285 | 325 |