# HG changeset patch # User Dmitry Volyntsev # Date 1571767551 -10800 # Node ID ca0858ef7d3de35137ab1c4d16cccd02b40396bd # Parent 9bc1ca0674490bdc172228559583b87f6f9087fd Tests: added js keys tests. diff --git a/js.t b/js.t --- a/js.t +++ b/js.t @@ -115,6 +115,10 @@ http { js_content return_method; } + location /arg_keys { + js_content arg_keys; + } + location /log { return 200 $test_log; } @@ -213,6 +217,10 @@ EOF r.return(Number(r.args.c), r.args.t); } + function arg_keys(r) { + r.return(200, Object.keys(r.args).sort()); + } + function test_log(r) { r.log('SEE-THIS'); } @@ -232,7 +240,7 @@ EOF EOF -$t->try_run('no njs available')->plan(26); +$t->try_run('no njs available')->plan(27); ############################################################################### @@ -270,6 +278,14 @@ like(http_get('/return_method?c=301&t=pa like(http_get('/return_method?c=404'), qr/404 Not.*html/s, 'return error page'); like(http_get('/return_method?c=inv'), qr/ 500 /, 'return invalid'); +TODO: { +local $TODO = 'not yet' + unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.3.7'; + +like(http_get('/arg_keys?b=1&c=2&a=5'), qr/a,b,c/m, 'r.args sorted keys'); + +} + like(http_get('/var'), qr/variable=127.0.0.1/, 'r.variables'); like(http_get('/global'), qr/global=njs/, 'global code'); like(http_get('/log'), qr/200 OK/, 'r.log'); diff --git a/js_headers.t b/js_headers.t --- a/js_headers.t +++ b/js_headers.t @@ -88,6 +88,10 @@ http { location /ihdr_out { js_content ihdr_out; } + + location /hdr_sorted_keys { + js_content hdr_sorted_keys; + } } } @@ -151,6 +155,19 @@ EOF r.return(200, s); } + function hdr_sorted_keys(r) { + var s = ''; + var hdr = r.args.in ? r.headersIn : r.headersOut; + + if (!r.args.in) { + r.headersOut.b = 'b'; + r.headersOut.c = 'c'; + r.headersOut.a = 'a'; + } + + r.return(200, Object.keys(hdr).sort()); + } + function test_foo_in(r) { return 'hdr=' + r.headersIn.foo; } @@ -196,7 +213,7 @@ EOF EOF -$t->try_run('no njs')->plan(16); +$t->try_run('no njs')->plan(18); ############################################################################### @@ -251,4 +268,23 @@ like(http( } +TODO: { +local $TODO = 'not yet' + unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.3.7'; + +like(http( + 'GET /hdr_sorted_keys?in=1 HTTP/1.0' . CRLF + . 'Cookie: foo1' . CRLF + . 'Accept: */*' . CRLF + . 'Cookie: foo2' . CRLF + . 'Host: localhost' . CRLF . CRLF +), qr/Accept,Cookie,Host/, 'r.headersIn sorted keys'); + +like(http( + 'GET /hdr_sorted_keys HTTP/1.0' . CRLF + . 'Host: localhost' . CRLF . CRLF +), qr/a,b,c/, 'r.headersOut sorted keys'); + +} + ###############################################################################