comparison js2.t @ 1413:215f3357034b

Tests: njs http global code.
author Dmitry Volyntsev <xeioex@nginx.com>
date Tue, 11 Dec 2018 14:12:44 +0300
parents 32156faf018e
children
comparison
equal deleted inserted replaced
1412:aaaa8a40250b 1413:215f3357034b
44 js_set $test_hdr_in test_hdr_in; 44 js_set $test_hdr_in test_hdr_in;
45 js_set $test_ihdr_in test_ihdr_in; 45 js_set $test_ihdr_in test_ihdr_in;
46 js_set $test_arg test_arg; 46 js_set $test_arg test_arg;
47 js_set $test_iarg test_iarg; 47 js_set $test_iarg test_iarg;
48 js_set $test_var test_var; 48 js_set $test_var test_var;
49 js_set $test_global test_global;
49 js_set $test_log test_log; 50 js_set $test_log test_log;
50 js_set $test_except test_except; 51 js_set $test_except test_except;
51 52
52 js_include test.js; 53 js_include test.js;
53 54
93 94
94 location /var { 95 location /var {
95 return 200 $test_var; 96 return 200 $test_var;
96 } 97 }
97 98
99 location /global {
100 return 200 $test_global;
101 }
102
98 location /body { 103 location /body {
99 js_content request_body; 104 js_content request_body;
100 } 105 }
101 106
102 location /in_file { 107 location /in_file {
159 } 164 }
160 165
161 EOF 166 EOF
162 167
163 $t->write_file('test.js', <<EOF); 168 $t->write_file('test.js', <<EOF);
169 var global = ['n', 'j', 's'].join("");
170
164 function test_njs(r) { 171 function test_njs(r) {
165 r.return(200, njs.version); 172 r.return(200, njs.version);
166 } 173 }
167 174
168 function test_method(r) { 175 function test_method(r) {
211 218
212 function test_var(r) { 219 function test_var(r) {
213 return 'variable=' + r.variables.remote_addr; 220 return 'variable=' + r.variables.remote_addr;
214 } 221 }
215 222
223 function test_global(r) {
224 return 'global=' + global;
225 }
226
216 function status(r) { 227 function status(r) {
217 r.status = 204; 228 r.status = 204;
218 r.sendHeader(); 229 r.sendHeader();
219 r.finish(); 230 r.finish();
220 } 231 }
311 function content_empty(r) { 322 function content_empty(r) {
312 } 323 }
313 324
314 EOF 325 EOF
315 326
316 $t->try_run('no njs available')->plan(34); 327 $t->try_run('no njs available')->plan(35);
317 328
318 ############################################################################### 329 ###############################################################################
319 330
320 TODO: { 331 TODO: {
321 local $TODO = 'not yet' 332 local $TODO = 'not yet'
361 like(http_get('/return_method?c=inv'), qr/ 500 /, 'return invalid'); 372 like(http_get('/return_method?c=inv'), qr/ 500 /, 'return invalid');
362 373
363 like(http_get('/return_headers'), qr/Foo: bar/, 'return headers'); 374 like(http_get('/return_headers'), qr/Foo: bar/, 'return headers');
364 375
365 like(http_get('/var'), qr/variable=127.0.0.1/, 'r.variables'); 376 like(http_get('/var'), qr/variable=127.0.0.1/, 'r.variables');
377 like(http_get('/global'), qr/global=njs/, 'global code');
366 like(http_get('/log'), qr/200 OK/, 'r.log'); 378 like(http_get('/log'), qr/200 OK/, 'r.log');
367 379
368 http_get('/except'); 380 http_get('/except');
369 http_get('/content_except'); 381 http_get('/content_except');
370 382