@@ -2605,28 +2605,50 @@ func TestAnalyze_directiveSources_defaultBehavior(t *testing.T) {
2605
2605
func TestAnalyze_limit_req_zone (t * testing.T ) {
2606
2606
t .Parallel ()
2607
2607
testcases := map [string ]struct {
2608
- stmt * Directive
2609
- ctx blockCtx
2608
+ args [] string
2609
+ sources [] MatchFunc
2610
2610
wantErr bool
2611
2611
}{
2612
- "limit_req_zone ok http" : {
2613
- & Directive {
2614
- Directive : "limit_req_zone" ,
2615
- Args : []string {"$binary_remote_addr" , "zone=one:10m" , "rate=1r/s" , "sync" },
2616
- Line : 5 ,
2617
- },
2618
- blockCtx {"http" },
2619
- false ,
2612
+ "limit_req_zone_4_args_nplus_latest" : {
2613
+ args : []string {"$binary_remote_addr" , "zone=one:10m" , "rate=1r/s" , "sync" },
2614
+ sources : []MatchFunc {NgxPlusLatestDirectivesMatchFn },
2615
+ wantErr : false ,
2616
+ },
2617
+ "limit_req_zone_3_args_nplus_latest" : {
2618
+ args : []string {"$binary_remote_addr" , "zone=one:10m" , "rate=1r/s" },
2619
+ sources : []MatchFunc {NgxPlusLatestDirectivesMatchFn },
2620
+ wantErr : false ,
2621
+ },
2622
+ "limit_req_zone_4_args_oss_latest" : {
2623
+ args : []string {"$binary_remote_addr" , "zone=one:10m" , "rate=1r/s" , "sync" },
2624
+ sources : []MatchFunc {OssLatestDirectivesMatchFn },
2625
+ wantErr : true ,
2626
+ },
2627
+ "limit_req_zone_3_args_oss_latest" : {
2628
+ args : []string {"$binary_remote_addr" , "zone=one:10m" , "rate=1r/s" },
2629
+ sources : []MatchFunc {OssLatestDirectivesMatchFn },
2630
+ wantErr : false ,
2631
+ },
2632
+ "limit_req_zone_4_args_default_sources" : {
2633
+ args : []string {"$binary_remote_addr" , "zone=one:10m" , "rate=1r/s" , "sync" },
2634
+ wantErr : false ,
2635
+ },
2636
+ "limit_req_zone_3_args_default_sources" : {
2637
+ args : []string {"$binary_remote_addr" , "zone=one:10m" , "rate=1r/s" },
2638
+ wantErr : false ,
2620
2639
},
2621
2640
}
2622
2641
2623
2642
for name , tc := range testcases {
2624
2643
tc := tc
2625
2644
t .Run (name , func (t * testing.T ) {
2626
2645
t .Parallel ()
2627
- err := analyze ("nginx.conf" , tc .stmt , ";" , tc .ctx , & ParseOptions {
2628
- DirectiveSources : []MatchFunc {NgxPlusLatestDirectivesMatchFn , AppProtectWAFv4DirectivesMatchFn },
2629
- })
2646
+ stmt := & Directive {
2647
+ Directive : "limit_req_zone" ,
2648
+ Args : tc .args ,
2649
+ Line : 5 ,
2650
+ }
2651
+ err := analyze ("nginx.conf" , stmt , ";" , blockCtx {"http" }, & ParseOptions {DirectiveSources : tc .sources })
2630
2652
2631
2653
if ! tc .wantErr && err != nil {
2632
2654
t .Fatal (err )
0 commit comments