annotate js.t @ 1336:7a0d626ecd94

Tests: removed js.t TODOs for empty buffers, fixed in njs 0.2.0.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 05 Jun 2018 12:54:32 +0300
parents 746d9ffdbd26
children f168fc46c7a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
2
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
3 # (C) Roman Arutyunyan
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
4
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
5 # Tests for http JavaScript module.
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
6
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
7 ###############################################################################
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
8
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
9 use warnings;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
10 use strict;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
11
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
12 use Test::More;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
13
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
15
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
16 use lib 'lib';
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
17 use Test::Nginx;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
18
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
19 ###############################################################################
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
20
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
21 select STDERR; $| = 1;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
22 select STDOUT; $| = 1;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
23
864
460a9cadbd2f Tests: do not check for njs presence, just try js.t configuration.
Sergey Kandaurov <pluknet@nginx.com>
parents: 709
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http rewrite/)
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
25 ->write_file_expand('nginx.conf', <<'EOF');
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
26
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
27 %%TEST_GLOBALS%%
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
28
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
29 daemon off;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
30
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
31 events {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
32 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
33
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
34 http {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
35 %%TEST_GLOBALS_HTTP%%
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
36
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
37 js_set $test_method test_method;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
38 js_set $test_version test_version;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
39 js_set $test_addr test_addr;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
40 js_set $test_uri test_uri;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
41 js_set $test_hdr test_hdr;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
42 js_set $test_ihdr test_ihdr;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
43 js_set $test_arg test_arg;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
44 js_set $test_iarg test_iarg;
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
45 js_set $test_var test_var;
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
46 js_set $test_log test_log;
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
47 js_set $test_except test_except;
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
48
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
49 js_include test.js;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
50
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
51 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
52 listen 127.0.0.1:8080;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
53 server_name localhost;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
54
1333
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
55 location /njs {
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
56 js_content test_njs;
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
57 }
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
58
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
59 location /req_method {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
60 return 200 $test_method;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
61 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
62
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
63 location /req_version {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
64 return 200 $test_version;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
65 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
66
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
67 location /req_addr {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
68 return 200 $test_addr;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
69 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
70
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
71 location /req_uri {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
72 return 200 $test_uri;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
73 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
74
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
75 location /req_hdr {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
76 return 200 $test_hdr;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
77 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
78
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
79 location /req_ihdr {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
80 return 200 $test_ihdr;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
81 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
82
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
83 location /req_arg {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
84 return 200 $test_arg;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
85 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
86
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
87 location /req_iarg {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
88 return 200 $test_iarg;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
89 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
90
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
91 location /req_var {
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
92 return 200 $test_var;
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
93 }
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
94
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
95 location /req_log {
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
96 return 200 $test_log;
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
97 }
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
98
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
99 location /req_except {
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
100 return 200 $test_except;
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
101 }
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
102
1331
f48d2792730e Tests: added njs empty js_content handler test.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
103 location /req_empty {
f48d2792730e Tests: added njs empty js_content handler test.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
104 js_content content_empty;
f48d2792730e Tests: added njs empty js_content handler test.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
105 }
f48d2792730e Tests: added njs empty js_content handler test.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
106
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
107 location /res_status {
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
108 js_content status;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
109 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
110
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
111 location /res_ctype {
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
112 js_content ctype;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
113 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
114
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
115 location /res_clen {
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
116 js_content clen;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
117 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
118
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
119 location /res_send {
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
120 js_content send;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
121 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
122
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
123 location /res_hdr {
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
124 js_content hdr;
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
125 }
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
126
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
127 location /res_ihdr {
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
128 js_content ihdr;
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
129 }
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
130
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
131 location /res_except {
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
132 js_content content_except;
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
133 }
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
134 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
135 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
136
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
137 EOF
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
138
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
139 $t->write_file('test.js', <<EOF);
1333
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
140 function test_njs(req, res) {
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
141 res.return(200, njs.version);
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
142 }
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
143
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
144 function test_method(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
145 return 'method=' + req.method;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
146 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
147
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
148 function test_version(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
149 return 'version=' + req.httpVersion;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
150 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
151
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
152 function test_addr(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
153 return 'addr=' + req.remoteAddress;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
154 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
155
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
156 function test_uri(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
157 return 'uri=' + req.uri;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
158 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
159
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
160 function test_hdr(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
161 return 'hdr=' + req.headers.foo;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
162 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
163
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
164 function test_ihdr(req, res) {
1106
4b0b10e39a08 Tests: fixed implicitly declared njs variables after 4337ed48d6d6.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1001
diff changeset
165 var s = '', h;
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
166 for (h in req.headers) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
167 if (h.substr(0, 3) == 'foo') {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
168 s += req.headers[h];
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
169 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
170 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
171 return s;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
172 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
173
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
174 function test_arg(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
175 return 'arg=' + req.args.foo;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
176 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
177
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
178 function test_iarg(req, res) {
1106
4b0b10e39a08 Tests: fixed implicitly declared njs variables after 4337ed48d6d6.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1001
diff changeset
179 var s = '', a;
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
180 for (a in req.args) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
181 if (a.substr(0, 3) == 'foo') {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
182 s += req.args[a];
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
183 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
184 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
185 return s;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
186 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
187
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
188 function test_var(req, res) {
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
189 return 'variable=' + req.variables.remote_addr;
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
190 }
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
191
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
192 function test_log(req, res) {
1315
890516ca898a Tests: reverted 3882f8f3b2bc to unbreak with njs 0.1.15.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1310
diff changeset
193 req.log("SEE-THIS");
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
194 }
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
195
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
196 function test_except(req, res) {
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
197 var fs = require('fs');
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
198 fs.readFileSync();
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
199 }
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
200
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
201 function status(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
202 res.status = 204;
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
203 if (res.status != 204)
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
204 res.status = 404;
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
205 res.sendHeader();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
206 res.finish();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
207 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
208
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
209 function ctype(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
210 res.status = 200;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
211 res.contentType = 'application/foo';
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
212 res.sendHeader();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
213 res.finish();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
214 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
215
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
216 function clen(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
217 res.status = 200;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
218 res.contentLength = 5;
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
219 if (res.contentLength != 5)
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
220 res.contentLength = 6;
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
221 res.sendHeader();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
222 res.send('foo12');
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
223 res.finish();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
224 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
225
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
226 function send(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
227 var a, s;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
228 res.status = 200;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
229 res.sendHeader();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
230 for (a in req.args) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
231 if (a.substr(0, 3) == 'foo') {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
232 s = req.args[a];
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
233 res.send('n=' + a + ', v=' + s.substr(0, 2) + ' ');
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
234 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
235 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
236 res.finish();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
237 }
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
238
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
239 function hdr(req, res) {
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
240 res.status = 200;
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
241 res.headers['Foo'] = req.args.fOO;
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
242
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
243 if (req.args.bar) {
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
244 res.headers['Bar'] = res.headers['Foo'];
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
245 }
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
246
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
247 if (req.args.bar == 'empty') {
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
248 res.headers['Bar'] = res.headers['Baz'];
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
249 }
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
250
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
251 res.sendHeader();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
252 res.finish();
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
253 }
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
254
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
255 function ihdr(req, res) {
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
256 res.status = 200;
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
257 res.headers['a'] = req.args.a;
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
258 res.headers['b'] = req.args.b;
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
259
1106
4b0b10e39a08 Tests: fixed implicitly declared njs variables after 4337ed48d6d6.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1001
diff changeset
260 var s = '', h;
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
261 for (h in res.headers) {
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
262 s += res.headers[h];
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
263 }
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
264
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
265 res.sendHeader();
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
266 res.send(s);
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
267 res.finish();
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
268 }
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
269
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
270 function content_except(req, res) {
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
271 JSON.parse({}.a.a);
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
272 }
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
273
1331
f48d2792730e Tests: added njs empty js_content handler test.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
274 function content_empty(req, res) {
f48d2792730e Tests: added njs empty js_content handler test.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
275 }
f48d2792730e Tests: added njs empty js_content handler test.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
276
993
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
277 EOF
3ee5ca1ec728 Tests: updated js.t to the new http js module syntax.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
278
1331
f48d2792730e Tests: added njs empty js_content handler test.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
279 $t->try_run('no njs available')->plan(23);
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
280
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
281 ###############################################################################
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
282
994
345a655ef643 Tests: fixed js.t tests description.
Sergey Kandaurov <pluknet@nginx.com>
parents: 993
diff changeset
283 like(http_get('/req_method'), qr/method=GET/, 'req.method');
345a655ef643 Tests: fixed js.t tests description.
Sergey Kandaurov <pluknet@nginx.com>
parents: 993
diff changeset
284 like(http_get('/req_version'), qr/version=1.0/, 'req.httpVersion');
345a655ef643 Tests: fixed js.t tests description.
Sergey Kandaurov <pluknet@nginx.com>
parents: 993
diff changeset
285 like(http_get('/req_addr'), qr/addr=127.0.0.1/, 'req.remoteAddress');
345a655ef643 Tests: fixed js.t tests description.
Sergey Kandaurov <pluknet@nginx.com>
parents: 993
diff changeset
286 like(http_get('/req_uri'), qr/uri=\/req_uri/, 'req.uri');
345a655ef643 Tests: fixed js.t tests description.
Sergey Kandaurov <pluknet@nginx.com>
parents: 993
diff changeset
287 like(http_get_hdr('/req_hdr'), qr/hdr=12345/, 'req.headers');
345a655ef643 Tests: fixed js.t tests description.
Sergey Kandaurov <pluknet@nginx.com>
parents: 993
diff changeset
288 like(http_get_ihdr('/req_ihdr'), qr/12345barz/, 'req.headers iteration');
345a655ef643 Tests: fixed js.t tests description.
Sergey Kandaurov <pluknet@nginx.com>
parents: 993
diff changeset
289 like(http_get('/req_arg?foO=12345'), qr/arg=12345/, 'req.args');
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
290 like(http_get('/req_iarg?foo=12345&foo2=bar&nn=22&foo-3=z'), qr/12345barz/,
994
345a655ef643 Tests: fixed js.t tests description.
Sergey Kandaurov <pluknet@nginx.com>
parents: 993
diff changeset
291 'req.args iteration');
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
292 like(http_get('/req_var'), qr/variable=127.0.0.1/, 'req.variables');
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
293 like(http_get('/req_log'), qr/200 OK/, 'req.log');
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
294
994
345a655ef643 Tests: fixed js.t tests description.
Sergey Kandaurov <pluknet@nginx.com>
parents: 993
diff changeset
295 like(http_get('/res_status'), qr/204 No Content/, 'res.status');
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
296 like(http_get('/res_ctype'), qr/Content-Type: application\/foo/,
994
345a655ef643 Tests: fixed js.t tests description.
Sergey Kandaurov <pluknet@nginx.com>
parents: 993
diff changeset
297 'res.contentType');
345a655ef643 Tests: fixed js.t tests description.
Sergey Kandaurov <pluknet@nginx.com>
parents: 993
diff changeset
298 like(http_get('/res_clen'), qr/Content-Length: 5/, 'res.contentLength');
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
299 like(http_get('/res_send?foo=12345&n=11&foo-2=bar&ndd=&foo-3=z'),
994
345a655ef643 Tests: fixed js.t tests description.
Sergey Kandaurov <pluknet@nginx.com>
parents: 993
diff changeset
300 qr/n=foo, v=12 n=foo-2, v=ba n=foo-3, v=z/, 'res.send');
345a655ef643 Tests: fixed js.t tests description.
Sergey Kandaurov <pluknet@nginx.com>
parents: 993
diff changeset
301 like(http_get('/res_hdr?foo=12345'), qr/Foo: 12345/, 'res.headers');
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
302 like(http_get('/res_hdr?foo=123&bar=copy'), qr/Bar: 123/, 'res.headers get');
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
303 like(http_get('/res_hdr?bar=empty'), qr/Bar: \x0d/, 'res.headers empty');
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
304 like(http_get('/res_ihdr?a=12&b=34'), qr/^1234$/m, 'res.headers iteration');
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
305
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
306 http_get('/req_except');
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
307 http_get('/res_except');
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
308
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
309 like(http_get('/res_ihdr'), qr/\x0d\x0a?\x0d\x0a?$/m, 'res.send zero');
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
310
1333
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
311 TODO: {
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
312 local $TODO = 'not yet'
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
313 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.2.1';
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
314 like(http_get('/req_empty'), qr/500 Internal Server Error/, 'empty handler');
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
315 }
746d9ffdbd26 Tests: fixed empty js_content test committed in f48d2792730e.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1331
diff changeset
316
1001
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
317 $t->stop();
4a0e1d7cc20b Tests: more JavaScript tests for http js module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 994
diff changeset
318
1315
890516ca898a Tests: reverted 3882f8f3b2bc to unbreak with njs 0.1.15.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1310
diff changeset
319 ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'log js');
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
320 ok(index($t->read_file('error.log'), 'at fs.readFileSync') > 0,
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
321 'js_set backtrace');
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
322 ok(index($t->read_file('error.log'), 'at JSON.parse') > 0,
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1106
diff changeset
323 'js_content backtrace');
708
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
324
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
325 ###############################################################################
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
326
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
327 sub http_get_hdr {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
328 my ($url, %extra) = @_;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
329 return http(<<EOF, %extra);
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
330 GET $url HTTP/1.0
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
331 FoO: 12345
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
332
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
333 EOF
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
334 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
335
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
336 sub http_get_ihdr {
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
337 my ($url, %extra) = @_;
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
338 return http(<<EOF, %extra);
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
339 GET $url HTTP/1.0
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
340 foo: 12345
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
341 Host: localhost
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
342 foo2: bar
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
343 X-xxx: more
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
344 foo-3: z
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
345
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
346 EOF
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
347 }
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
348
71a2d58c0a7f Tests: JavaScript tests.
Roman Arutyunyan <arut@nginx.com>
parents:
diff changeset
349 ###############################################################################