Skip to content

Commit 1fb7499

Browse files
Tests: fine-tuning of js2.t.
1 parent e8dd01e commit 1fb7499

File tree

1 file changed

+37
-38
lines changed

1 file changed

+37
-38
lines changed

js2.t

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ events {
3737
http {
3838
%%TEST_GLOBALS_HTTP%%
3939
40-
js_set $test_method test_method;
41-
js_set $test_version test_version;
42-
js_set $test_addr test_addr;
43-
js_set $test_uri test_uri;
44-
js_set $test_hdr test_hdr;
45-
js_set $test_ihdr test_ihdr;
46-
js_set $test_arg test_arg;
47-
js_set $test_iarg test_iarg;
48-
js_set $test_var test_var;
49-
js_set $test_log test_log;
50-
js_set $test_except test_except;
40+
js_set $test_method test_method;
41+
js_set $test_version test_version;
42+
js_set $test_addr test_addr;
43+
js_set $test_uri test_uri;
44+
js_set $test_hdr_in test_hdr_in;
45+
js_set $test_ihdr_in test_ihdr_in;
46+
js_set $test_arg test_arg;
47+
js_set $test_iarg test_iarg;
48+
js_set $test_var test_var;
49+
js_set $test_log test_log;
50+
js_set $test_except test_except;
5151
5252
js_include test.js;
5353
@@ -76,11 +76,11 @@ http {
7676
}
7777
7878
location /hdr_in {
79-
return 200 $test_hdr;
79+
return 200 $test_hdr_in;
8080
}
8181
8282
location /ihdr_in {
83-
return 200 $test_ihdr;
83+
return 200 $test_ihdr_in;
8484
}
8585
8686
location /arg {
@@ -132,7 +132,7 @@ http {
132132
js_content send;
133133
}
134134
135-
location /return {
135+
location /return_method {
136136
js_content return_method;
137137
}
138138
@@ -144,7 +144,7 @@ http {
144144
return 200 $test_log;
145145
}
146146
147-
location /var_except {
147+
location /except {
148148
return 200 $test_except;
149149
}
150150
@@ -181,11 +181,11 @@ $t->write_file('test.js', <<EOF);
181181
return 'uri=' + r.uri;
182182
}
183183
184-
function test_hdr(r) {
184+
function test_hdr_in(r) {
185185
return 'hdr=' + r.headersIn.foo;
186186
}
187187
188-
function test_ihdr(r) {
188+
function test_ihdr_in(r) {
189189
var s = '', h;
190190
for (h in r.headersIn) {
191191
if (h.substr(0, 3) == 'foo') {
@@ -215,8 +215,6 @@ $t->write_file('test.js', <<EOF);
215215
216216
function status(r) {
217217
r.status = 204;
218-
if (r.status != 204)
219-
r.status = 404;
220218
r.sendHeader();
221219
r.finish();
222220
}
@@ -231,8 +229,6 @@ $t->write_file('test.js', <<EOF);
231229
function clen(r) {
232230
r.status = 200;
233231
r.headersOut['Content-Length'] = 5;
234-
if (r.headersOut['Content-Length'] != 5)
235-
r.headersOut['Content-Length'] = 6;
236232
r.sendHeader();
237233
r.send('foo12');
238234
r.finish();
@@ -243,11 +239,8 @@ $t->write_file('test.js', <<EOF);
243239
r.headersOut['Foo'] = r.args.fOO;
244240
245241
if (r.args.bar) {
246-
r.headersOut['Bar'] = r.headersOut['Foo'];
247-
}
248-
249-
if (r.args.bar == 'empty') {
250-
r.headersOut['Bar'] = r.headersOut['Baz'];
242+
r.headersOut['Bar'] =
243+
r.headersOut[(r.args.bar == 'empty' ? 'Baz' :'Foo')]
251244
}
252245
253246
r.sendHeader();
@@ -302,7 +295,7 @@ $t->write_file('test.js', <<EOF);
302295
}
303296
304297
function test_log(r) {
305-
r.log("SEE-THIS");
298+
r.log('SEE-THIS');
306299
}
307300
308301
function test_except(r) {
@@ -320,7 +313,7 @@ $t->write_file('test.js', <<EOF);
320313
321314
EOF
322315

323-
$t->try_run('no njs available')->plan(32);
316+
$t->try_run('no njs available')->plan(34);
324317

325318
###############################################################################
326319

@@ -344,42 +337,48 @@ like(http_get('/clen'), qr/Content-Length: 5/, 'r.headersOut.contentLength');
344337
like(http_get('/hdr_out?foo=12345'), qr/Foo: 12345/, 'r.headersOut');
345338
like(http_get('/hdr_out?foo=123&bar=copy'), qr/Bar: 123/, 'r.headersOut get');
346339
like(http_get('/hdr_out?bar=empty'), qr/Bar: \x0d/, 'r.headersOut empty');
340+
like(http_get('/hdr_out?foo='), qr/Foo: \x0d/, 'r.headersOut no value');
341+
like(http_get('/hdr_out?foo'), qr/Foo: \x0d/, 'r.headersOut no value 2');
347342
like(http_get('/ihdr_out?a=12&b=34'), qr/^1234$/m, 'r.headersOut iteration');
348343
like(http_get('/ihdr_out'), qr/\x0d\x0a?\x0d\x0a?$/m, 'r.send zero');
349344

350345
like(http_post('/body'), qr/REQ-BODY/, 'request body');
351346
like(http_post('/in_file'), qr/request body is in a file/,
352347
'request body in file');
353348
like(http_post_big('/body'), qr/200.*^(1234567890){1024}$/ms,
354-
'request body big');
349+
'request body big');
355350

356351
like(http_get('/send?foo=12345&n=11&foo-2=bar&ndd=&foo-3=z'),
357352
qr/n=foo, v=12 n=foo-2, v=ba n=foo-3, v=z/, 'r.send');
358353

359-
like(http_get('/return?c=200'), qr/200 OK.*\x0d\x0a?\x0d\x0a?$/s, 'return code');
360-
like(http_get('/return?c=200&t=SEE-THIS'), qr/200 OK.*^SEE-THIS$/ms, 'return text');
361-
like(http_get('/return?c=301&t=path'), qr/ 301 .*Location: path/s, 'return redirect');
362-
like(http_get('/return?c=404'), qr/404 Not.*html/s, 'return error page');
363-
like(http_get('/return?c=inv'), qr/ 500 /, 'return invalid');
354+
like(http_get('/return_method?c=200'), qr/200 OK.*\x0d\x0a?\x0d\x0a?$/s,
355+
'return code');
356+
like(http_get('/return_method?c=200&t=SEE-THIS'), qr/200 OK.*^SEE-THIS$/ms,
357+
'return text');
358+
like(http_get('/return_method?c=301&t=path'), qr/ 301 .*Location: path/s,
359+
'return redirect');
360+
like(http_get('/return_method?c=404'), qr/404 Not.*html/s, 'return error page');
361+
like(http_get('/return_method?c=inv'), qr/ 500 /, 'return invalid');
364362

365363
like(http_get('/return_headers'), qr/Foo: bar/, 'return headers');
366364

367365
like(http_get('/var'), qr/variable=127.0.0.1/, 'r.variables');
368366
like(http_get('/log'), qr/200 OK/, 'r.log');
369367

370-
http_get('/var_except');
368+
http_get('/except');
371369
http_get('/content_except');
372370

373-
like(http_get('/content_empty'), qr/500 Internal Server Error/, 'empty handler');
371+
like(http_get('/content_empty'), qr/500 Internal Server Error/,
372+
'empty handler');
374373
}
375374

376375
$t->stop();
377376

378377
ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'log js');
379378
ok(index($t->read_file('error.log'), 'at fs.readFileSync') > 0,
380-
'js_set backtrace');
379+
'js_set backtrace');
381380
ok(index($t->read_file('error.log'), 'at JSON.parse') > 0,
382-
'js_content backtrace');
381+
'js_content backtrace');
383382

384383
###############################################################################
385384

0 commit comments

Comments
 (0)