/
options.t
586 lines (434 loc) · 10.7 KB
/
options.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# vi:ft= et ts=4 sw=4
use lib 't/lib';
use Test::Resty;
plan tests => blocks() * 3;
run_tests();
__DATA__
=== TEST 1: bad --nginx value
--- opts: --nginx=/tmp/no/such/file
--- src
print("arg 0: ", arg[0])
print("arg 1: ", arg[1])
print("arg 2: ", arg[2])
print("arg 3: ", arg[3])
--- out
--- err_like chop
(?:Can't exec|valgrind:) "?/tmp/no/such/file"?: No such file or directory
--- ret: 2
=== TEST 2: -V
--- opts: -V
--- out
--- err_like eval
qr/^resty \d+.\d{2}
nginx version: /s
--- ret: 0
=== TEST 3: -h
--- opts: -h
--- out
resty [options] [lua-file [args]]
Options:
-c NUM Set maximal connection count (default: 64).
-e PROG Run the inlined Lua code in "prog".
--gdb Use GDB to run the underlying C process.
--help Print this help.
--errlog-level LEVEL
Set nginx error_log level.
Can be debug, info, notice, warn, error, crit, alert,
or emerg.
--http-conf CONF Specifies nginx.conf snippet inserted into the http {}
configuration block (multiple instances are supported).
--http-include PATH Include the specified file in the nginx http
configuration block (multiple instances are supported).
-I DIR Add dir to the search paths for Lua libraries.
-j dump Use LuaJIT's jit.dump module to output detailed info of
the traces generated by the JIT compiler.
-j off Turn off the LuaJIT JIT compiler.
-j v Use LuaJIT's jit.v module to output brief info of the
traces generated by the JIT compiler.
-l LIB Require library "lib".
--main-include PATH Include the specified file in the nginx main
configuration block (multiple instances are supported).
--ns IP Specify a custom name server (multiple instances are
supported).
--resolve-ipv6 Make the nginx resolver lookup both IPv4 and IPv6
addresses.
--rr Use Mozilla rr to record the execution of the
underlying C process.
--shdict 'NAME SIZE'
Create the specified lua shared dicts in the http
configuration block (multiple instances are supported).
--nginx Specify the nginx path (this option might be removed
in the future).
-V Print version numbers and nginx configurations.
--valgrind Use valgrind to run nginx.
--valgrind-opts Pass extra options to valgrind.
For bug reporting instructions, please see:
<https://openresty.org/en/community.html>
Copyright (C) Yichun Zhang (agentzh). All rights reserved.
--- err
--- ret: 0
=== TEST 4: bad --http-include value
--- opts: --http-include=/tmp/no/such/file
--- src
--- out
--- err_like chop
Could not find http include '/tmp/no/such/file'
--- ret: 2
=== TEST 5: bad --main-include value
--- opts: --main-include=/tmp/no/such/file
--- src
--- out
--- err_like chop
Could not find main include '/tmp/no/such/file'
--- ret: 2
=== TEST 6: bad --main-include file content
--- opts: --main-include=/tmp/a.conf
--- user_files
>>> /tmp/a.conf
lua_shared_dict dogs 1m;
--- src
local dogs = ngx.shared.dogs
dogs:set("Tom", 32)
print(dogs:get("Tom"))
--- out
--- err
nginx: [emerg] "lua_shared_dict" directive is not allowed here in /tmp/a.conf:1
--- ret: 1
=== TEST 7: good --http-include file content
--- opts: --http-include=/tmp/a.conf
--- user_files
>>> /tmp/a.conf
lua_shared_dict dogs 1m;
--- src
local dogs = ngx.shared.dogs
dogs:set("Tom", 32)
print(dogs:get("Tom"))
--- out
32
--- err
=== TEST 8: multiple --http-include options
--- opts: --http-include=/tmp/a.conf --http-include=/tmp/b.conf
--- user_files
>>> /tmp/a.conf
lua_shared_dict dogs 1m;
>>> /tmp/b.conf
lua_shared_dict cats 1m;
--- src
local dogs = ngx.shared.dogs
local cats = ngx.shared.cats
dogs:set("Tom", 32)
cats:set("Tom", 12)
print("dog: ", dogs:get("Tom"))
print("cat: ", cats:get("Tom"))
--- out
dog: 32
cat: 12
--- err
=== TEST 9: multiple --main-include options
--- opts: --main-include=/tmp/a.conf --main-include=/tmp/b.conf
--- user_files
>>> /tmp/a.conf
env foo=32;
>>> /tmp/b.conf
env bar=56;
--- src
print("foo: ", os.getenv("foo"))
print("bar: ", os.getenv("bar"))
--- out
foo: 32
bar: 56
--- err
=== TEST 10: good --http-include file content (relative path)
--- opts: --http-include=t/tmp/a.conf
--- user_files
>>> a.conf
lua_shared_dict dogs 1m;
--- src
local dogs = ngx.shared.dogs
dogs:set("Tom", 32)
print(dogs:get("Tom"))
--- out
32
--- err
=== TEST 11: --http-include + -e
--- opts: --http-include=t/tmp/a.conf -e 'local dogs = ngx.shared.dogs dogs:set("Tom", 32) print(dogs:get("Tom"))'
--- user_files
>>> a.conf
lua_shared_dict dogs 1m;
--- out
32
--- err
=== TEST 12: good --main-include option value (relative path)
--- opts: --main-include=/tmp/a.conf --main-include=/tmp/b.conf
--- user_files
>>> /tmp/a.conf
env foo=32;
>>> /tmp/b.conf
env bar=56;
--- src
print("foo: ", os.getenv("foo"))
print("bar: ", os.getenv("bar"))
--- out
foo: 32
bar: 56
--- err
=== TEST 13: --shdict option
--- opts: '--shdict=dogs 12k'
--- src
local dogs = ngx.shared.dogs
dogs:set("Tom", 32)
print(dogs:get("Tom"))
--- out
32
--- err
=== TEST 14: multiple --shdict option
--- opts: '--shdict=dogs 1m' '--shdict=cats 1m'
--- src
local dogs = ngx.shared.dogs
dogs:set("Tom", 32)
print(dogs:get("Tom"))
local cats = ngx.shared.cats
dogs:set("Max", 64)
print(dogs:get("Max"))
--- out
32
64
--- err
=== TEST 15: --shdict option missing size
--- opts: '--shdict=dogs'
--- out
--- err
Invalid value for --shdict option. Expected: NAME SIZE
--- ret: 255
=== TEST 16: --shdict option case-insensitive size (1/2)
--- opts: '--shdict=dogs 1m'
--- src
local dogs = ngx.shared.dogs
dogs:set("Tom", 32)
print(dogs:get("Tom"))
--- out
32
--- err
=== TEST 17: --shdict option case-insensitive size (2/2)
--- opts: '--shdict=dogs 1M'
--- src
local dogs = ngx.shared.dogs
dogs:set("Tom", 32)
print(dogs:get("Tom"))
--- out
32
--- err
=== TEST 18: --shdict option permissive format
--- opts: '--shdict=cats_dogs 20000'
--- src
local dict = ngx.shared.cats_dogs
dict:set("Tom", 32)
print(dict:get("Tom"))
--- out
32
--- err
=== TEST 19: multiple -e options
--- opts: -e 'print(1)' -e 'print(2)'
--- out
1
2
--- err
=== TEST 20: multiple -e options with file
--- opts: -e 'print(1)' -e 'print(2)'
--- src
print(3)
--- out
1
2
3
--- err
=== TEST 21: multiple -e options with single quotes
--- opts: -e "print('1')" -e 'print(2)'
--- out
1
2
--- err
=== TEST 22: resolver has ipv6=off by default
--- src
local conf = ngx.config.prefix() .. "conf/nginx.conf"
local file = assert(io.open(conf, "r"))
print(file:read "*a")
file:close()
--- out_like
resolver [\s\S]* ipv6=off;
--- err
=== TEST 23: --resolve-ipv6 flag enables ipv6 resolution
--- opts: --resolve-ipv6
--- src
local conf = ngx.config.prefix() .. "conf/nginx.conf"
local file = assert(io.open(conf, "r"))
print(file:read "*a")
file:close()
--- out_not_like
resolver [\s\S]* ipv6=off;
--- err
=== TEST 24: specified name server overrides system name servers
--- opts: --ns 127.0.0.1
--- src
local conf = ngx.config.prefix() .. "conf/nginx.conf"
local file = assert(io.open(conf, "r"))
print(file:read "*a")
file:close()
--- out_like
resolver 127.0.0.1 ipv6=off;
--- err
=== TEST 25: multiple ns flags can be specified
--- opts: --ns 127.0.0.1 --ns 127.0.0.2
--- src
local conf = ngx.config.prefix() .. "conf/nginx.conf"
local file = assert(io.open(conf, "r"))
print(file:read "*a")
file:close()
--- out_like
resolver 127.0.0.1 127.0.0.2 ipv6=off;
--- err
=== TEST 26: ns flags can be specified in both ipv4 and ipv6 formats
--- opts: --ns 127.0.0.1 --ns 127.0.0.2 --ns [::1] --ns [2003:dead:beef:4dad:23:46:bb:101]
--- src
local conf = ngx.config.prefix() .. "conf/nginx.conf"
local file = assert(io.open(conf, "r"))
print(file:read "*a")
file:close()
print(str)
--- out_like
resolver 127.0.0.1 127.0.0.2 \[::1\] \[2003:dead:beef:4dad:23:46:bb:101\] ipv6=off;
--- err
=== TEST 27: ns flag works with resolve ipv6 flag
--- opts: --ns 127.0.0.1 --resolve-ipv6
--- src
local conf = ngx.config.prefix() .. "conf/nginx.conf"
local file = assert(io.open(conf, "r"))
print(file:read "*a")
file:close()
print(str)
--- out_like
resolver 127.0.0.1;
--- err
=== TEST 28: returns error message on invalid name server ip
--- opts: --ns invalid
--- src
--- out
--- err
Invalid value for --ns option. Expected: IP
--- ret: 255
=== TEST 29: --http-conf
--- opts: --http-conf 'lua_shared_dict dogs 1m;'
--- src
ngx.say(ngx.shared.dogs and "yes" or "no")
--- out
yes
--- err
=== TEST 30: --valgrind & --gdb
--- opts: --valgrind --gdb
--- src
print("hi")
--- out
--- err
ERROR: options --gdb and --valgrind cannot be specified at the same time.
--- ret: 25
=== TEST 31: --gdb & --rr
--- opts: --gdb --rr
--- src
print("hi")
--- out
--- err
ERROR: options --gdb and --rr cannot be specified at the same time.
--- ret: 25
=== TEST 32: --rr & --valgrind
--- opts: --rr --valgrind
--- src
print("hi")
--- out
--- err
ERROR: options --rr and --valgrind cannot be specified at the same time.
--- ret: 25
=== TEST 33: --errrlog-level debug
--- opts: --errlog-level debug
--- src
ngx.log(ngx.DEBUG, 'debug message')
--- out
--- err_like
1: debug message
=== TEST 34: -l
--- opts: -l t.tmp.testfile
--- user_files
>>> testfile.lua
print(1)
--- out
1
--- err
=== TEST 35: multiple -l
--- opts: -l t.tmp.testfile -l t.tmp.otherfile
--- user_files
>>> testfile.lua
print(1)
>>> otherfile.lua
print(2)
--- out
1
2
--- err
=== TEST 36: -l with -e
--- opts: -e 'print(1)' -l t.tmp.testfile
--- user_files
>>> testfile.lua
print(2)
--- out
1
2
--- err
=== TEST 37: multiple -l with -e
--- opts: -e print(1) -l t.tmp.testfile -e print(3) -l t.tmp.otherfile
--- user_files
>>> testfile.lua
print(2)
>>> otherfile.lua
print(4)
--- out
1
2
3
4
--- err
=== TEST 38: -l with file
--- opts: -l t.tmp.testfile
--- user_files
>>> testfile.lua
print(1)
--- src
print(2)
--- out
1
2
--- err
=== TEST 39: bad -l value
--- opts: -l missing
--- out
--- err_like chop
module 'missing' not found
--- ret: 1
=== TEST 40: -l is quoted
--- opts: -l t.tmp.testfile.one'two"three
--- out
--- err_like chop
module 't.tmp.testfile.one'two"three' not found
--- ret: 1
=== TEST 41: -j v
--- opts: -j v -e 'for i = 1, 200 do end'
--- out
--- err
[TRACE 1 (command line -e):1 loop]
=== TEST 42: -j dump
--- opts: -j dump -e 'for i = 1, 200 do end'
--- out_like chop
TRACE 1 IR.*? TRACE 1 mcode
--- err
=== TEST 43: -j off
--- opts: -j off -e 'require "jit.v".on() for i = 1, 200 do end'
--- out
--- err