Mercurial > hg > nginx-tests
comparison js.t @ 1751:18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Thu, 09 Dec 2021 17:36:29 +0000 |
parents | 456bf219d768 |
children | 410072f42157 |
comparison
equal
deleted
inserted
replaced
1750:b28f88e352dd | 1751:18ac4d9e5a2a |
---|---|
35 } | 35 } |
36 | 36 |
37 http { | 37 http { |
38 %%TEST_GLOBALS_HTTP%% | 38 %%TEST_GLOBALS_HTTP%% |
39 | 39 |
40 js_set $test_method test_method; | 40 js_set $test_method test.method; |
41 js_set $test_version test_version; | 41 js_set $test_version test.version; |
42 js_set $test_addr test_addr; | 42 js_set $test_addr test.addr; |
43 js_set $test_uri test_uri; | 43 js_set $test_uri test.uri; |
44 js_set $test_arg test_arg; | 44 js_set $test_arg test.arg; |
45 js_set $test_iarg test_iarg; | 45 js_set $test_iarg test.iarg; |
46 js_set $test_var test_var; | 46 js_set $test_var test.variable; |
47 js_set $test_type test_type; | 47 js_set $test_type test.type; |
48 js_set $test_global test_global; | 48 js_set $test_global test.global_obj; |
49 js_set $test_log test_log; | 49 js_set $test_log test.log; |
50 js_set $test_except test_except; | 50 js_set $test_except test.except; |
51 | 51 |
52 js_include test.js; | 52 js_import test.js; |
53 | 53 |
54 server { | 54 server { |
55 listen 127.0.0.1:8080; | 55 listen 127.0.0.1:8080; |
56 server_name localhost; | 56 server_name localhost; |
57 | 57 |
58 location /njs { | 58 location /njs { |
59 js_content test_njs; | 59 js_content test.njs; |
60 } | 60 } |
61 | 61 |
62 location /method { | 62 location /method { |
63 return 200 $test_method; | 63 return 200 $test_method; |
64 } | 64 } |
90 location /global { | 90 location /global { |
91 return 200 $test_global; | 91 return 200 $test_global; |
92 } | 92 } |
93 | 93 |
94 location /body { | 94 location /body { |
95 js_content request_body; | 95 js_content test.request_body; |
96 } | 96 } |
97 | 97 |
98 location /in_file { | 98 location /in_file { |
99 client_body_in_file_only on; | 99 client_body_in_file_only on; |
100 js_content request_body; | 100 js_content test.request_body; |
101 } | 101 } |
102 | 102 |
103 location /status { | 103 location /status { |
104 js_content status; | 104 js_content test.status; |
105 } | 105 } |
106 | 106 |
107 location /request_body { | 107 location /request_body { |
108 js_content request_body; | 108 js_content test.request_body; |
109 } | 109 } |
110 | 110 |
111 location /request_body_cache { | 111 location /request_body_cache { |
112 js_content request_body_cache; | 112 js_content test.request_body_cache; |
113 } | 113 } |
114 | 114 |
115 location /send { | 115 location /send { |
116 js_content send; | 116 js_content test.send; |
117 } | 117 } |
118 | 118 |
119 location /return_method { | 119 location /return_method { |
120 js_content return_method; | 120 js_content test.return_method; |
121 } | 121 } |
122 | 122 |
123 location /arg_keys { | 123 location /arg_keys { |
124 js_content arg_keys; | 124 js_content test.arg_keys; |
125 } | 125 } |
126 | 126 |
127 location /type { | 127 location /type { |
128 js_content test_type; | 128 js_content test.type; |
129 } | 129 } |
130 | 130 |
131 location /log { | 131 location /log { |
132 return 200 $test_log; | 132 return 200 $test_log; |
133 } | 133 } |
135 location /except { | 135 location /except { |
136 return 200 $test_except; | 136 return 200 $test_except; |
137 } | 137 } |
138 | 138 |
139 location /content_except { | 139 location /content_except { |
140 js_content content_except; | 140 js_content test.content_except; |
141 } | 141 } |
142 | 142 |
143 location /content_empty { | 143 location /content_empty { |
144 js_content content_empty; | 144 js_content test.content_empty; |
145 } | 145 } |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 EOF | 149 EOF |
153 | 153 |
154 function test_njs(r) { | 154 function test_njs(r) { |
155 r.return(200, njs.version); | 155 r.return(200, njs.version); |
156 } | 156 } |
157 | 157 |
158 function test_method(r) { | 158 function method(r) { |
159 return 'method=' + r.method; | 159 return 'method=' + r.method; |
160 } | 160 } |
161 | 161 |
162 function test_version(r) { | 162 function version(r) { |
163 return 'version=' + r.httpVersion; | 163 return 'version=' + r.httpVersion; |
164 } | 164 } |
165 | 165 |
166 function test_addr(r) { | 166 function addr(r) { |
167 return 'addr=' + r.remoteAddress; | 167 return 'addr=' + r.remoteAddress; |
168 } | 168 } |
169 | 169 |
170 function test_uri(r) { | 170 function uri(r) { |
171 return 'uri=' + r.uri; | 171 return 'uri=' + r.uri; |
172 } | 172 } |
173 | 173 |
174 function test_arg(r) { | 174 function arg(r) { |
175 return 'arg=' + r.args.foo; | 175 return 'arg=' + r.args.foo; |
176 } | 176 } |
177 | 177 |
178 function test_iarg(r) { | 178 function iarg(r) { |
179 var s = '', a; | 179 var s = '', a; |
180 for (a in r.args) { | 180 for (a in r.args) { |
181 if (a.substr(0, 3) == 'foo') { | 181 if (a.substr(0, 3) == 'foo') { |
182 s += r.args[a]; | 182 s += r.args[a]; |
183 } | 183 } |
184 } | 184 } |
185 return s; | 185 return s; |
186 } | 186 } |
187 | 187 |
188 function test_var(r) { | 188 function variable(r) { |
189 return 'variable=' + r.variables.remote_addr; | 189 return 'variable=' + r.variables.remote_addr; |
190 } | 190 } |
191 | 191 |
192 function test_global(r) { | 192 function global_obj(r) { |
193 return 'global=' + global; | 193 return 'global=' + global; |
194 } | 194 } |
195 | 195 |
196 function status(r) { | 196 function status(r) { |
197 r.status = 204; | 197 r.status = 204; |
234 | 234 |
235 function arg_keys(r) { | 235 function arg_keys(r) { |
236 r.return(200, Object.keys(r.args).sort()); | 236 r.return(200, Object.keys(r.args).sort()); |
237 } | 237 } |
238 | 238 |
239 function test_type(r) { | 239 function type(r) { |
240 var p = r.args.path.split('.').reduce((a, v) => a[v], r); | 240 var p = r.args.path.split('.').reduce((a, v) => a[v], r); |
241 | 241 |
242 var type = Buffer.isBuffer(p) ? 'buffer' : (typeof p); | 242 var typ = Buffer.isBuffer(p) ? 'buffer' : (typeof p); |
243 r.return(200, `type: \${type}`); | 243 r.return(200, `type: \${typ}`); |
244 } | 244 } |
245 | 245 |
246 function test_log(r) { | 246 function log(r) { |
247 r.log('SEE-LOG'); | 247 r.log('SEE-LOG'); |
248 } | 248 } |
249 | 249 |
250 function test_except(r) { | 250 function except(r) { |
251 var fs = require('fs'); | 251 var fs = require('fs'); |
252 fs.readFileSync(); | 252 fs.readFileSync(); |
253 } | 253 } |
254 | 254 |
255 | 255 |
257 JSON.parse({}.a.a); | 257 JSON.parse({}.a.a); |
258 } | 258 } |
259 | 259 |
260 function content_empty(r) { | 260 function content_empty(r) { |
261 } | 261 } |
262 | |
263 export default {njs:test_njs, method, version, addr, uri, arg, iarg, | |
264 variable, global_obj, status, request_body, | |
265 request_body_cache, send, return_method, arg_keys, | |
266 type, log, except, content_except, content_empty}; | |
262 | 267 |
263 EOF | 268 EOF |
264 | 269 |
265 $t->try_run('no njs available')->plan(33); | 270 $t->try_run('no njs available')->plan(33); |
266 | 271 |