Mercurial > hg > nginx-tests
comparison js.t @ 1001:4a0e1d7cc20b
Tests: more JavaScript tests for http js module.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 01 Aug 2016 18:27:21 +0300 |
parents | 345a655ef643 |
children | 4b0b10e39a08 |
comparison
equal
deleted
inserted
replaced
1000:577a5899a33d | 1001:4a0e1d7cc20b |
---|---|
40 js_set $test_uri test_uri; | 40 js_set $test_uri test_uri; |
41 js_set $test_hdr test_hdr; | 41 js_set $test_hdr test_hdr; |
42 js_set $test_ihdr test_ihdr; | 42 js_set $test_ihdr test_ihdr; |
43 js_set $test_arg test_arg; | 43 js_set $test_arg test_arg; |
44 js_set $test_iarg test_iarg; | 44 js_set $test_iarg test_iarg; |
45 js_set $test_var test_var; | |
46 js_set $test_log test_log; | |
45 | 47 |
46 js_include test.js; | 48 js_include test.js; |
47 | 49 |
48 server { | 50 server { |
49 listen 127.0.0.1:8080; | 51 listen 127.0.0.1:8080; |
79 | 81 |
80 location /req_iarg { | 82 location /req_iarg { |
81 return 200 $test_iarg; | 83 return 200 $test_iarg; |
82 } | 84 } |
83 | 85 |
86 location /req_var { | |
87 return 200 $test_var; | |
88 } | |
89 | |
90 location /req_log { | |
91 return 200 $test_log; | |
92 } | |
93 | |
84 location /res_status { | 94 location /res_status { |
85 js_content status; | 95 js_content status; |
86 } | 96 } |
87 | 97 |
88 location /res_ctype { | 98 location /res_ctype { |
97 js_content send; | 107 js_content send; |
98 } | 108 } |
99 | 109 |
100 location /res_hdr { | 110 location /res_hdr { |
101 js_content hdr; | 111 js_content hdr; |
112 } | |
113 | |
114 location /res_ihdr { | |
115 js_content ihdr; | |
102 } | 116 } |
103 } | 117 } |
104 } | 118 } |
105 | 119 |
106 EOF | 120 EOF |
150 } | 164 } |
151 } | 165 } |
152 return s; | 166 return s; |
153 } | 167 } |
154 | 168 |
169 function test_var(req, res) { | |
170 return 'variable=' + req.variables.remote_addr; | |
171 } | |
172 | |
173 function test_log(req, res) { | |
174 req.log("SEE-THIS"); | |
175 } | |
176 | |
155 function status(req, res) { | 177 function status(req, res) { |
156 res.status = 204; | 178 res.status = 204; |
179 if (res.status != 204) | |
180 res.status = 404; | |
157 res.sendHeader(); | 181 res.sendHeader(); |
158 res.finish(); | 182 res.finish(); |
159 } | 183 } |
160 | 184 |
161 function ctype(req, res) { | 185 function ctype(req, res) { |
166 } | 190 } |
167 | 191 |
168 function clen(req, res) { | 192 function clen(req, res) { |
169 res.status = 200; | 193 res.status = 200; |
170 res.contentLength = 5; | 194 res.contentLength = 5; |
195 if (res.contentLength != 5) | |
196 res.contentLength = 6; | |
171 res.sendHeader(); | 197 res.sendHeader(); |
172 res.send('foo12'); | 198 res.send('foo12'); |
173 res.finish(); | 199 res.finish(); |
174 } | 200 } |
175 | 201 |
187 } | 213 } |
188 | 214 |
189 function hdr(req, res) { | 215 function hdr(req, res) { |
190 res.status = 200; | 216 res.status = 200; |
191 res.headers['Foo'] = req.args.fOO; | 217 res.headers['Foo'] = req.args.fOO; |
192 res.sendHeader(); | 218 |
219 if (req.args.bar) { | |
220 res.headers['Bar'] = res.headers['Foo']; | |
221 } | |
222 | |
223 if (req.args.bar == 'empty') { | |
224 res.headers['Bar'] = res.headers['Baz']; | |
225 } | |
226 | |
227 res.sendHeader(); | |
228 res.finish(); | |
229 } | |
230 | |
231 function ihdr(req, res) { | |
232 res.status = 200; | |
233 res.headers['a'] = req.args.a; | |
234 res.headers['b'] = req.args.b; | |
235 | |
236 s = ''; | |
237 for (h in res.headers) { | |
238 s += res.headers[h]; | |
239 } | |
240 | |
241 res.sendHeader(); | |
242 res.send(s); | |
193 res.finish(); | 243 res.finish(); |
194 } | 244 } |
195 EOF | 245 EOF |
196 | 246 |
197 $t->try_run('no njs available')->plan(13); | 247 $t->try_run('no njs available')->plan(20); |
198 | 248 |
199 ############################################################################### | 249 ############################################################################### |
200 | 250 |
201 like(http_get('/req_method'), qr/method=GET/, 'req.method'); | 251 like(http_get('/req_method'), qr/method=GET/, 'req.method'); |
202 like(http_get('/req_version'), qr/version=1.0/, 'req.httpVersion'); | 252 like(http_get('/req_version'), qr/version=1.0/, 'req.httpVersion'); |
205 like(http_get_hdr('/req_hdr'), qr/hdr=12345/, 'req.headers'); | 255 like(http_get_hdr('/req_hdr'), qr/hdr=12345/, 'req.headers'); |
206 like(http_get_ihdr('/req_ihdr'), qr/12345barz/, 'req.headers iteration'); | 256 like(http_get_ihdr('/req_ihdr'), qr/12345barz/, 'req.headers iteration'); |
207 like(http_get('/req_arg?foO=12345'), qr/arg=12345/, 'req.args'); | 257 like(http_get('/req_arg?foO=12345'), qr/arg=12345/, 'req.args'); |
208 like(http_get('/req_iarg?foo=12345&foo2=bar&nn=22&foo-3=z'), qr/12345barz/, | 258 like(http_get('/req_iarg?foo=12345&foo2=bar&nn=22&foo-3=z'), qr/12345barz/, |
209 'req.args iteration'); | 259 'req.args iteration'); |
260 like(http_get('/req_var'), qr/variable=127.0.0.1/, 'req.variables'); | |
261 like(http_get('/req_log'), qr/200 OK/, 'req.log'); | |
210 | 262 |
211 like(http_get('/res_status'), qr/204 No Content/, 'res.status'); | 263 like(http_get('/res_status'), qr/204 No Content/, 'res.status'); |
212 like(http_get('/res_ctype'), qr/Content-Type: application\/foo/, | 264 like(http_get('/res_ctype'), qr/Content-Type: application\/foo/, |
213 'res.contentType'); | 265 'res.contentType'); |
214 like(http_get('/res_clen'), qr/Content-Length: 5/, 'res.contentLength'); | 266 like(http_get('/res_clen'), qr/Content-Length: 5/, 'res.contentLength'); |
215 like(http_get('/res_send?foo=12345&n=11&foo-2=bar&ndd=&foo-3=z'), | 267 like(http_get('/res_send?foo=12345&n=11&foo-2=bar&ndd=&foo-3=z'), |
216 qr/n=foo, v=12 n=foo-2, v=ba n=foo-3, v=z/, 'res.send'); | 268 qr/n=foo, v=12 n=foo-2, v=ba n=foo-3, v=z/, 'res.send'); |
217 like(http_get('/res_hdr?foo=12345'), qr/Foo: 12345/, 'res.headers'); | 269 like(http_get('/res_hdr?foo=12345'), qr/Foo: 12345/, 'res.headers'); |
270 like(http_get('/res_hdr?foo=123&bar=copy'), qr/Bar: 123/, 'res.headers get'); | |
271 like(http_get('/res_hdr?bar=empty'), qr/Bar: \x0d/, 'res.headers empty'); | |
272 like(http_get('/res_ihdr?a=12&b=34'), qr/^1234$/m, 'res.headers iteration'); | |
273 | |
274 TODO: { | |
275 local $TODO = 'zero size buf in writer'; | |
276 | |
277 like(http_get('/res_ihdr'), qr/\x0d\x0a?\x0d\x0a?$/m, 'res.send zero'); | |
278 | |
279 $t->todo_alerts(); | |
280 | |
281 } | |
282 | |
283 $t->stop(); | |
284 | |
285 ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'log js'); | |
218 | 286 |
219 ############################################################################### | 287 ############################################################################### |
220 | 288 |
221 sub http_get_hdr { | 289 sub http_get_hdr { |
222 my ($url, %extra) = @_; | 290 my ($url, %extra) = @_; |