comparison js.t @ 1787:e55aa7021ea5

Tests: added js r.internal test.
author Dmitry Volyntsev <xeioex@nginx.com>
date Thu, 25 Aug 2022 16:53:15 -0700
parents 386748f328b1
children 7cf848422b28
comparison
equal deleted inserted replaced
1786:cadf15e2e2b3 1787:e55aa7021ea5
43 js_set $test_uri test.uri; 43 js_set $test_uri test.uri;
44 js_set $test_var test.variable; 44 js_set $test_var test.variable;
45 js_set $test_type test.type; 45 js_set $test_type test.type;
46 js_set $test_global test.global_obj; 46 js_set $test_global test.global_obj;
47 js_set $test_log test.log; 47 js_set $test_log test.log;
48 js_set $test_internal test.sub_internal;
48 js_set $test_except test.except; 49 js_set $test_except test.except;
49 50
50 js_import test.js; 51 js_import test.js;
51 52
52 server { 53 server {
114 js_content test.type; 115 js_content test.type;
115 } 116 }
116 117
117 location /log { 118 location /log {
118 return 200 $test_log; 119 return 200 $test_log;
120 }
121
122 location /internal {
123 js_content test.internal;
124 }
125
126 location /sub_internal {
127 internal;
128 return 200 $test_internal;
119 } 129 }
120 130
121 location /except { 131 location /except {
122 return 200 $test_except; 132 return 200 $test_except;
123 } 133 }
213 223
214 function log(r) { 224 function log(r) {
215 r.log('SEE-LOG'); 225 r.log('SEE-LOG');
216 } 226 }
217 227
228 async function internal(r) {
229 let reply = await r.subrequest('/sub_internal');
230
231 r.return(200, `parent: \${r.internal} sub: \${reply.responseText}`);
232 }
233
234 function sub_internal(r) {
235 return r.internal;
236 }
237
218 function except(r) { 238 function except(r) {
219 var fs = require('fs'); 239 var fs = require('fs');
220 fs.readFileSync(); 240 fs.readFileSync();
221 } 241 }
222 242
227 247
228 function content_empty(r) { 248 function content_empty(r) {
229 } 249 }
230 250
231 export default {njs:test_njs, method, version, addr, uri, 251 export default {njs:test_njs, method, version, addr, uri,
232 variable, global_obj, status, request_body, 252 variable, global_obj, status, request_body, internal,
233 request_body_cache, send, return_method, 253 request_body_cache, send, return_method, sub_internal,
234 type, log, except, content_except, content_empty}; 254 type, log, except, content_except, content_empty};
235 255
236 EOF 256 EOF
237 257
238 $t->try_run('no njs available')->plan(26); 258 $t->try_run('no njs available')->plan(27);
239 259
240 ############################################################################### 260 ###############################################################################
241 261
242 like(http_get('/method'), qr/method=GET/, 'r.method'); 262 like(http_get('/method'), qr/method=GET/, 'r.method');
243 like(http_get('/version'), qr/version=1.0/, 'r.httpVersion'); 263 like(http_get('/version'), qr/version=1.0/, 'r.httpVersion');
283 } 303 }
284 304
285 like(http_get('/var'), qr/variable=127.0.0.1/, 'r.variables'); 305 like(http_get('/var'), qr/variable=127.0.0.1/, 'r.variables');
286 like(http_get('/global'), qr/global=njs/, 'global code'); 306 like(http_get('/global'), qr/global=njs/, 'global code');
287 like(http_get('/log'), qr/200 OK/, 'r.log'); 307 like(http_get('/log'), qr/200 OK/, 'r.log');
308
309 TODO: {
310 local $TODO = 'not yet'
311 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.7';
312
313 like(http_get('/internal'), qr/parent: false sub: true/, 'r.internal');
314
315 }
288 316
289 http_get('/except'); 317 http_get('/except');
290 http_get('/content_except'); 318 http_get('/content_except');
291 319
292 like(http_get('/content_empty'), qr/500 Internal Server Error/, 320 like(http_get('/content_empty'), qr/500 Internal Server Error/,