comparison js_fetch_objects.t @ 1821:1792ba2e8026

Tests: fixed js tests for Fetch API for nginx-1.22 and below. The fix is to move a test with multiple headers returned by $http_a variable under an nginx version check.
author Dmitry Volyntsev <xeioex@nginx.com>
date Mon, 06 Feb 2023 09:36:13 -0800
parents 1d88487eafbf
children de6aeda5c274
comparison
equal deleted inserted replaced
1820:84b6bb8d74e5 1821:1792ba2e8026
57 js_content test.response; 57 js_content test.response;
58 } 58 }
59 59
60 location /fetch { 60 location /fetch {
61 js_content test.fetch; 61 js_content test.fetch;
62 }
63
64 location /fetch_multi_header {
65 js_content test.fetch_multi_header;
62 } 66 }
63 67
64 location /method { 68 location /method {
65 return 200 $request_method; 69 return 200 $request_method;
66 } 70 }
487 {body: 'foo'}); 491 {body: 'foo'});
488 var r = await ngx.fetch(req); 492 var r = await ngx.fetch(req);
489 var body = await r.text(); 493 var body = await r.text();
490 return `\${r.url}: \${r.status} \${body}`; 494 return `\${r.url}: \${r.status} \${body}`;
491 }, 'http://127.0.0.1:$p0/body: 201 foo'], 495 }, 'http://127.0.0.1:$p0/body: 201 foo'],
492 ['request body', async () => { 496 ];
497
498 run(r, tests);
499 }
500
501 async function fetch_multi_header(r) {
502 const tests = [
503 ['request multi header', async () => {
493 var h = new Headers({a: 'X'}); 504 var h = new Headers({a: 'X'});
494 h.append('a', 'Z'); 505 h.append('a', 'Z');
495 var req = new Request("http://127.0.0.1:$p0/header", 506 var req = new Request("http://127.0.0.1:$p0/header",
496 {headers: h}); 507 {headers: h});
497 var r = await ngx.fetch(req); 508 var r = await ngx.fetch(req);
498 var body = await r.text(); 509 var body = await r.text();
499 return `\${r.url}: \${r.status} \${body}`; 510 return `\${r.url}: \${r.status} \${body}`;
500 }, 'http://127.0.0.1:$p0/header: 200 X, Z'], 511 }, 'http://127.0.0.1:$p0/header: 200 X, Z'],
501 ]; 512 ];
502 513
503 run(r, tests); 514 run(r, tests);
504 } 515 }
505 516
506 export default {njs: test_njs, body, headers, request, response, fetch}; 517 export default {njs: test_njs, body, headers, request, response, fetch,
518 fetch_multi_header};
507 EOF 519 EOF
508 520
509 $t->try_run('no njs')->plan(4); 521 $t->try_run('no njs')->plan(5);
510 522
511 ############################################################################### 523 ###############################################################################
512 524
513 local $TODO = 'not yet' unless has_version('0.7.10'); 525 local $TODO = 'not yet' unless has_version('0.7.10');
514 526
515 like(http_get('/headers'), qr/200 OK/s, 'headers tests'); 527 like(http_get('/headers'), qr/200 OK/s, 'headers tests');
516 like(http_get('/request'), qr/200 OK/s, 'request tests'); 528 like(http_get('/request'), qr/200 OK/s, 'request tests');
517 like(http_get('/response'), qr/200 OK/s, 'response tests'); 529 like(http_get('/response'), qr/200 OK/s, 'response tests');
518 like(http_get('/fetch'), qr/200 OK/s, 'fetch tests'); 530 like(http_get('/fetch'), qr/200 OK/s, 'fetch tests');
531
532 TODO: {
533 local $TODO = 'not yet' unless $t->has_version('1.23.0');
534
535 like(http_get('/fetch_multi_header'), qr/200 OK/s,
536 'fetch multi header tests');
537
538 }
519 539
520 ############################################################################### 540 ###############################################################################
521 541
522 sub has_version { 542 sub has_version {
523 my $need = shift; 543 my $need = shift;