comparison js_subrequests.t @ 1614:bc0990ea2e5b

Tests: js TODO adjusted up to 0.4.0.
author Dmitry Volyntsev <xeioex@nginx.com>
date Tue, 17 Nov 2020 17:49:16 +0000
parents 726877fc4b08
children cd0461e1e392
comparison
equal deleted inserted replaced
1613:d7ec131d305a 1614:bc0990ea2e5b
50 50
51 server { 51 server {
52 listen 127.0.0.1:8080; 52 listen 127.0.0.1:8080;
53 server_name localhost; 53 server_name localhost;
54 54
55 location /njs {
56 js_content test_njs;
57 }
58
59 location /sr { 55 location /sr {
60 js_content sr; 56 js_content sr;
61 } 57 }
62 58
63 location /sr_pr { 59 location /sr_pr {
256 252
257 EOF 253 EOF
258 254
259 $t->write_file('test.js', <<EOF); 255 $t->write_file('test.js', <<EOF);
260 this.Failed = {get toConvert() { return {toString(){return {};}}}}; 256 this.Failed = {get toConvert() { return {toString(){return {};}}}};
261
262 function test_njs(r) {
263 r.return(200, njs.version);
264 }
265 257
266 function sr(r) { 258 function sr(r) {
267 subrequest_fn(r, ['/p/sub2'], ['uri', 'status']) 259 subrequest_fn(r, ['/p/sub2'], ['uri', 'status'])
268 } 260 }
269 261
516 '[{"status":404,"uri":"/unknown"},' . 508 '[{"status":404,"uri":"/unknown"},' .
517 '{"status":206,"uri":"/p/sub1"},' . 509 '{"status":206,"uri":"/p/sub1"},' .
518 '{"status":200,"uri":"/p/delayed"}]', 510 '{"status":200,"uri":"/p/delayed"}]',
519 'sr_multi'); 511 'sr_multi');
520 512
521 my $ver = http_get('/njs');
522
523 TODO: {
524 local $TODO = 'not yet'
525 unless $ver =~ /^([.0-9]+)$/m && $1 ge '0.3.8';
526
527 is(get_json('/sr_pr'), '{"h":"xxx"}', 'sr_promise'); 513 is(get_json('/sr_pr'), '{"h":"xxx"}', 'sr_promise');
528 is(get_json('/sr_options_args_pr'), '{"h":"xxx"}', 'sr_options_args_pr'); 514 is(get_json('/sr_options_args_pr'), '{"h":"xxx"}', 'sr_options_args_pr');
529 is(get_json('/sr_options_method_pr?m=PUT'), '["PUT"]', 'sr method PUT'); 515 is(get_json('/sr_options_method_pr?m=PUT'), '["PUT"]', 'sr method PUT');
530 is(get_json('/sr_body_pr'), '{"a":{"b":1}}', 'sr_body_pr'); 516 is(get_json('/sr_body_pr'), '{"a":{"b":1}}', 'sr_body_pr');
531 is(get_json('/sr_js_in_subrequest_pr'), '["JS-SUB"]', 'sr_js_in_subrequest_pr'); 517 is(get_json('/sr_js_in_subrequest_pr'), '["JS-SUB"]', 'sr_js_in_subrequest_pr');
532 is(get_json('/sr_unavail_pr'), '[{"status":502,"uri":"/unavail"}]', 518 is(get_json('/sr_unavail_pr'), '[{"status":502,"uri":"/unavail"}]',
533 'sr_unavail_pr'); 519 'sr_unavail_pr');
534 520
535 }
536
537 TODO: {
538 local $TODO = 'not yet'
539 unless $ver =~ /^([.0-9]+)$/m && $1 ge '0.3.9';
540
541 like(http_get('/sr_detached_in_variable_handler'), qr/subrequest_var/, 521 like(http_get('/sr_detached_in_variable_handler'), qr/subrequest_var/,
542 'sr_detached_in_variable_handler'); 522 'sr_detached_in_variable_handler');
543 }
544 523
545 http_get('/sr_broken'); 524 http_get('/sr_broken');
546 http_get('/sr_in_sr'); 525 http_get('/sr_in_sr');
547 http_get('/sr_in_variable_handler'); 526 http_get('/sr_in_variable_handler');
548 http_get('/sr_error_page'); 527 http_get('/sr_error_page');
569 'subrequest creation failed'); 548 'subrequest creation failed');
570 ok(index($t->read_file('error.log'), 549 ok(index($t->read_file('error.log'),
571 'js subrequest: failed to get the parent context') > 0, 550 'js subrequest: failed to get the parent context') > 0,
572 'zero parent ctx'); 551 'zero parent ctx');
573 552
574 TODO: {
575 local $TODO = 'not yet'
576 unless $ver =~ /^([.0-9]+)$/m && $1 ge '0.3.9';
577
578 ok(index($t->read_file('error.log'), 'DETACHED') > 0, 553 ok(index($t->read_file('error.log'), 'DETACHED') > 0,
579 'detached subrequest'); 554 'detached subrequest');
580 }
581 555
582 ############################################################################### 556 ###############################################################################
583 557
584 sub recode { 558 sub recode {
585 my $json; 559 my $json;