Mercurial > hg > nginx-tests
comparison js_subrequests.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 | 5ac6efbe5552 |
children | f89770df737a |
comparison
equal
deleted
inserted
replaced
1750:b28f88e352dd | 1751:18ac4d9e5a2a |
---|---|
41 %%TEST_GLOBALS_HTTP%% | 41 %%TEST_GLOBALS_HTTP%% |
42 | 42 |
43 proxy_cache_path %%TESTDIR%%/cache1 | 43 proxy_cache_path %%TESTDIR%%/cache1 |
44 keys_zone=ON:1m use_temp_path=on; | 44 keys_zone=ON:1m use_temp_path=on; |
45 | 45 |
46 js_include test.js; | 46 js_import test.js; |
47 | 47 |
48 js_set $async_var async_var; | 48 js_set $async_var test.async_var; |
49 js_set $subrequest_var subrequest_var; | 49 js_set $subrequest_var test.subrequest_var; |
50 | 50 |
51 server { | 51 server { |
52 listen 127.0.0.1:8080; | 52 listen 127.0.0.1:8080; |
53 server_name localhost; | 53 server_name localhost; |
54 | 54 |
55 location /njs { | 55 location /njs { |
56 js_content test_njs; | 56 js_content test.njs; |
57 } | 57 } |
58 | 58 |
59 location /sr { | 59 location /sr { |
60 js_content sr; | 60 js_content test.sr; |
61 } | 61 } |
62 | 62 |
63 location /sr_pr { | 63 location /sr_pr { |
64 js_content sr_pr; | 64 js_content test.sr_pr; |
65 } | 65 } |
66 | 66 |
67 location /sr_args { | 67 location /sr_args { |
68 js_content sr_args; | 68 js_content test.sr_args; |
69 } | 69 } |
70 | 70 |
71 location /sr_options_args { | 71 location /sr_options_args { |
72 js_content sr_options_args; | 72 js_content test.sr_options_args; |
73 } | 73 } |
74 | 74 |
75 location /sr_options_args_pr { | 75 location /sr_options_args_pr { |
76 js_content sr_options_args_pr; | 76 js_content test.sr_options_args_pr; |
77 } | 77 } |
78 | 78 |
79 location /sr_options_method { | 79 location /sr_options_method { |
80 js_content sr_options_method; | 80 js_content test.sr_options_method; |
81 } | 81 } |
82 | 82 |
83 location /sr_options_method_pr { | 83 location /sr_options_method_pr { |
84 js_content sr_options_method_pr; | 84 js_content test.sr_options_method_pr; |
85 } | 85 } |
86 | 86 |
87 location /sr_options_body { | 87 location /sr_options_body { |
88 js_content sr_options_body; | 88 js_content test.sr_options_body; |
89 } | 89 } |
90 | 90 |
91 location /sr_options_method_head { | 91 location /sr_options_method_head { |
92 js_content sr_options_method_head; | 92 js_content test.sr_options_method_head; |
93 } | 93 } |
94 | 94 |
95 location /sr_body { | 95 location /sr_body { |
96 js_content sr_body; | 96 js_content test.sr_body; |
97 } | 97 } |
98 | 98 |
99 location /sr_body_pr { | 99 location /sr_body_pr { |
100 js_content sr_body_pr; | 100 js_content test.sr_body_pr; |
101 } | 101 } |
102 | 102 |
103 location /sr_body_special { | 103 location /sr_body_special { |
104 js_content sr_body_special; | 104 js_content test.sr_body_special; |
105 } | 105 } |
106 | 106 |
107 location /sr_in_variable_handler { | 107 location /sr_in_variable_handler { |
108 set $_ $async_var; | 108 set $_ $async_var; |
109 js_content sr_in_variable_handler; | 109 js_content test.sr_in_variable_handler; |
110 } | 110 } |
111 | 111 |
112 location /sr_detached_in_variable_handler { | 112 location /sr_detached_in_variable_handler { |
113 return 200 $subrequest_var; | 113 return 200 $subrequest_var; |
114 } | 114 } |
118 error_page 404 /return; | 118 error_page 404 /return; |
119 return 404; | 119 return 404; |
120 } | 120 } |
121 | 121 |
122 location /sr_error_page { | 122 location /sr_error_page { |
123 js_content sr_error_page; | 123 js_content test.sr_error_page; |
124 } | 124 } |
125 | 125 |
126 location /sr_js_in_subrequest { | 126 location /sr_js_in_subrequest { |
127 js_content sr_js_in_subrequest; | 127 js_content test.sr_js_in_subrequest; |
128 } | 128 } |
129 | 129 |
130 location /sr_js_in_subrequest_pr { | 130 location /sr_js_in_subrequest_pr { |
131 js_content sr_js_in_subrequest_pr; | 131 js_content test.sr_js_in_subrequest_pr; |
132 } | 132 } |
133 | 133 |
134 location /sr_file { | 134 location /sr_file { |
135 js_content sr_file; | 135 js_content test.sr_file; |
136 } | 136 } |
137 | 137 |
138 location /sr_cache { | 138 location /sr_cache { |
139 js_content sr_cache; | 139 js_content test.sr_cache; |
140 } | 140 } |
141 | 141 |
142 | 142 |
143 location /sr_unavail { | 143 location /sr_unavail { |
144 js_content sr_unavail; | 144 js_content test.sr_unavail; |
145 } | 145 } |
146 | 146 |
147 location /sr_unavail_pr { | 147 location /sr_unavail_pr { |
148 js_content sr_unavail_pr; | 148 js_content test.sr_unavail_pr; |
149 } | 149 } |
150 | 150 |
151 location /sr_broken { | 151 location /sr_broken { |
152 js_content sr_broken; | 152 js_content test.sr_broken; |
153 } | 153 } |
154 | 154 |
155 location /sr_too_large { | 155 location /sr_too_large { |
156 js_content sr_too_large; | 156 js_content test.sr_too_large; |
157 } | 157 } |
158 | 158 |
159 location /sr_out_of_order { | 159 location /sr_out_of_order { |
160 js_content sr_out_of_order; | 160 js_content test.sr_out_of_order; |
161 } | 161 } |
162 | 162 |
163 location /sr_except_not_a_func { | 163 location /sr_except_not_a_func { |
164 js_content sr_except_not_a_func; | 164 js_content test.sr_except_not_a_func; |
165 } | 165 } |
166 | 166 |
167 location /sr_except_failed_to_convert_options_arg { | 167 location /sr_except_failed_to_convert_options_arg { |
168 js_content sr_except_failed_to_convert_options_arg; | 168 js_content test.sr_except_failed_to_convert_options_arg; |
169 } | 169 } |
170 | 170 |
171 location /sr_except_invalid_options_header_only { | 171 location /sr_except_invalid_options_header_only { |
172 js_content sr_except_invalid_options_header_only; | 172 js_content test.sr_except_invalid_options_header_only; |
173 } | 173 } |
174 | 174 |
175 location /sr_in_sr_callback { | 175 location /sr_in_sr_callback { |
176 js_content sr_in_sr_callback; | 176 js_content test.sr_in_sr_callback; |
177 } | 177 } |
178 | 178 |
179 location /sr_uri_except { | 179 location /sr_uri_except { |
180 js_content sr_uri_except; | 180 js_content test.sr_uri_except; |
181 } | 181 } |
182 | 182 |
183 | 183 |
184 location /file/ { | 184 location /file/ { |
185 alias %%TESTDIR%%/; | 185 alias %%TESTDIR%%/; |
198 subrequest_output_buffer_size 3; | 198 subrequest_output_buffer_size 3; |
199 proxy_pass http://127.0.0.1:8081/; | 199 proxy_pass http://127.0.0.1:8081/; |
200 } | 200 } |
201 | 201 |
202 location /sr_in_sr { | 202 location /sr_in_sr { |
203 js_content sr_in_sr; | 203 js_content test.sr_in_sr; |
204 } | 204 } |
205 | 205 |
206 location /unavail { | 206 location /unavail { |
207 proxy_pass http://127.0.0.1:8084/; | 207 proxy_pass http://127.0.0.1:8084/; |
208 } | 208 } |
209 | 209 |
210 location /sr_parent { | 210 location /sr_parent { |
211 js_content sr_parent; | 211 js_content test.sr_parent; |
212 } | 212 } |
213 | 213 |
214 location /js_sub { | 214 location /js_sub { |
215 js_content js_sub; | 215 js_content test.js_sub; |
216 } | 216 } |
217 | 217 |
218 location /return { | 218 location /return { |
219 return 200 '["$request_method"]'; | 219 return 200 '["$request_method"]'; |
220 } | 220 } |
242 location /method { | 242 location /method { |
243 return 200 '["$request_method"]'; | 243 return 200 '["$request_method"]'; |
244 } | 244 } |
245 | 245 |
246 location /body { | 246 location /body { |
247 js_content body; | 247 js_content test.body; |
248 } | 248 } |
249 | 249 |
250 location /detached { | 250 location /detached { |
251 js_content detached; | 251 js_content test.detached; |
252 } | 252 } |
253 | 253 |
254 location /delayed { | 254 location /delayed { |
255 js_content delayed; | 255 js_content test.delayed; |
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 server { | 259 server { |
260 listen 127.0.0.1:8084; | 260 listen 127.0.0.1:8084; |
265 } | 265 } |
266 | 266 |
267 EOF | 267 EOF |
268 | 268 |
269 $t->write_file('test.js', <<EOF); | 269 $t->write_file('test.js', <<EOF); |
270 this.Failed = {get toConvert() { return {toString(){return {};}}}}; | |
271 | |
272 function test_njs(r) { | 270 function test_njs(r) { |
273 r.return(200, njs.version); | 271 r.return(200, njs.version); |
274 } | 272 } |
275 | 273 |
276 function sr(r) { | 274 function sr(r) { |
471 | 469 |
472 function sr_except_not_a_func(r) { | 470 function sr_except_not_a_func(r) { |
473 r.subrequest('/sub1', 'a=1', 'b'); | 471 r.subrequest('/sub1', 'a=1', 'b'); |
474 } | 472 } |
475 | 473 |
474 let Failed = {get toConvert() { return {toString(){return {};}}}}; | |
475 | |
476 function sr_except_failed_to_convert_options_arg(r) { | 476 function sr_except_failed_to_convert_options_arg(r) { |
477 r.subrequest('/sub1', {args:Failed.toConvert}, ()=>{}); | 477 r.subrequest('/sub1', {args:Failed.toConvert}, ()=>{}); |
478 } | 478 } |
479 | 479 |
480 function sr_uri_except(r) { | 480 function sr_uri_except(r) { |
486 } | 486 } |
487 | 487 |
488 function js_sub(r) { | 488 function js_sub(r) { |
489 r.return(200, '["JS-SUB"]'); | 489 r.return(200, '["JS-SUB"]'); |
490 } | 490 } |
491 | |
492 export default {njs:test_njs, sr, sr_pr, sr_args, sr_options_args, | |
493 sr_options_args_pr, sr_options_method, sr_options_method_pr, | |
494 sr_options_method_head, sr_options_body, sr_body, | |
495 sr_body_pr, sr_body_special, body, delayed, detached, | |
496 sr_in_variable_handler, async_var, sr_error_page, | |
497 subrequest_var, sr_file, sr_cache, sr_unavail, sr_parent, | |
498 sr_unavail_pr, sr_broken, sr_too_large, sr_in_sr, | |
499 sr_js_in_subrequest, sr_js_in_subrequest_pr, js_sub, | |
500 sr_in_sr_callback, sr_out_of_order, sr_except_not_a_func, | |
501 sr_uri_except, sr_except_failed_to_convert_options_arg}; | |
491 | 502 |
492 EOF | 503 EOF |
493 | 504 |
494 $t->write_file('t', '["SEE-THIS"]'); | 505 $t->write_file('t', '["SEE-THIS"]'); |
495 | 506 |