@@ -486,34 +486,72 @@ describe("NGINX conf compiler", function()
486
486
487
487
describe (" injected NGINX directives" , function ()
488
488
it (" injects proxy_access_log directive" , function ()
489
- local conf = assert (conf_loader (nil , {
489
+ local conf , nginx_conf
490
+ conf = assert (conf_loader (nil , {
490
491
proxy_access_log = " /dev/stdout" ,
491
492
stream_listen = " 0.0.0.0:9100" ,
492
493
nginx_stream_tcp_nodelay = " on" ,
493
494
}))
494
- local nginx_conf = prefix_handler .compile_kong_conf (conf )
495
+ nginx_conf = prefix_handler .compile_kong_conf (conf )
495
496
assert .matches (" access_log%s/dev/stdout%skong_log_format;" , nginx_conf )
496
- local nginx_conf = prefix_handler .compile_kong_stream_conf (conf )
497
+ nginx_conf = prefix_handler .compile_kong_stream_conf (conf )
497
498
assert .matches (" access_log%slogs/access.log%sbasic;" , nginx_conf )
498
499
499
- local conf = assert (conf_loader (nil , {
500
+ conf = assert (conf_loader (nil , {
500
501
proxy_access_log = " off" ,
501
502
stream_listen = " 0.0.0.0:9100" ,
502
503
nginx_stream_tcp_nodelay = " on" ,
503
504
}))
504
- local nginx_conf = prefix_handler .compile_kong_conf (conf )
505
+ nginx_conf = prefix_handler .compile_kong_conf (conf )
505
506
assert .matches (" access_log%soff;" , nginx_conf )
506
- local nginx_conf = prefix_handler .compile_kong_stream_conf (conf )
507
+ nginx_conf = prefix_handler .compile_kong_stream_conf (conf )
507
508
assert .matches (" access_log%slogs/access.log%sbasic;" , nginx_conf )
508
509
509
- local conf = assert (conf_loader (nil , {
510
+ conf = assert (conf_loader (nil , {
511
+ proxy_access_log = " /dev/stdout apigw-json" ,
512
+ nginx_http_log_format = ' apigw-json "$kong_request_id"' ,
513
+ stream_listen = " 0.0.0.0:9100" ,
514
+ nginx_stream_tcp_nodelay = " on" ,
515
+ }))
516
+ nginx_conf = prefix_handler .compile_kong_conf (conf )
517
+ assert .matches (" access_log%s/dev/stdout%sapigw%-json;" , nginx_conf )
518
+ nginx_conf = prefix_handler .compile_kong_stream_conf (conf )
519
+ assert .matches (" access_log%slogs/access.log%sbasic;" , nginx_conf )
520
+
521
+ -- configure an undefined log format will error
522
+ -- on kong start. This is expected
523
+ conf = assert (conf_loader (nil , {
524
+ proxy_access_log = " /dev/stdout not-exist" ,
525
+ nginx_http_log_format = ' apigw-json "$kong_request_id"' ,
526
+ stream_listen = " 0.0.0.0:9100" ,
527
+ nginx_stream_tcp_nodelay = " on" ,
528
+ }))
529
+ nginx_conf = prefix_handler .compile_kong_conf (conf )
530
+ assert .matches (" access_log%s/dev/stdout%snot%-exist;" , nginx_conf )
531
+ nginx_conf = prefix_handler .compile_kong_stream_conf (conf )
532
+ assert .matches (" access_log%slogs/access.log%sbasic;" , nginx_conf )
533
+
534
+ conf = assert (conf_loader (nil , {
535
+ proxy_access_log = " /tmp/not-exist.log" ,
536
+ stream_listen = " 0.0.0.0:9100" ,
537
+ nginx_stream_tcp_nodelay = " on" ,
538
+ }))
539
+ nginx_conf = prefix_handler .compile_kong_conf (conf )
540
+ assert .matches (" access_log%s/tmp/not%-exist.log%skong_log_format;" , nginx_conf )
541
+ nginx_conf = prefix_handler .compile_kong_stream_conf (conf )
542
+ assert .matches (" access_log%slogs/access.log%sbasic;" , nginx_conf )
543
+
544
+ conf = assert (conf_loader (nil , {
545
+ prefix = " servroot_tmp" ,
546
+ nginx_stream_log_format = " custom '$protocol $status'" ,
510
547
proxy_stream_access_log = " /dev/stdout custom" ,
511
548
stream_listen = " 0.0.0.0:9100" ,
512
549
nginx_stream_tcp_nodelay = " on" ,
513
550
}))
514
- local nginx_conf = prefix_handler .compile_kong_conf (conf )
551
+ assert (prefix_handler .prepare_prefix (conf ))
552
+ nginx_conf = prefix_handler .compile_kong_conf (conf )
515
553
assert .matches (" access_log%slogs/access.log%skong_log_format;" , nginx_conf )
516
- local nginx_conf = prefix_handler .compile_kong_stream_conf (conf )
554
+ nginx_conf = prefix_handler .compile_kong_stream_conf (conf )
517
555
assert .matches (" access_log%s/dev/stdout%scustom;" , nginx_conf )
518
556
end )
519
557
0 commit comments