Skip to content

Commit 2bbc14b

Browse files
authored
Merge pull request #107 from ryepup/limit-req-tests
test: expand limit_req_zone coverage
2 parents 7ccbf75 + 249db13 commit 2bbc14b

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

analyze_test.go

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,28 +2605,50 @@ func TestAnalyze_directiveSources_defaultBehavior(t *testing.T) {
26052605
func TestAnalyze_limit_req_zone(t *testing.T) {
26062606
t.Parallel()
26072607
testcases := map[string]struct {
2608-
stmt *Directive
2609-
ctx blockCtx
2608+
args []string
2609+
sources []MatchFunc
26102610
wantErr bool
26112611
}{
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,
26202639
},
26212640
}
26222641

26232642
for name, tc := range testcases {
26242643
tc := tc
26252644
t.Run(name, func(t *testing.T) {
26262645
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})
26302652

26312653
if !tc.wantErr && err != nil {
26322654
t.Fatal(err)

0 commit comments

Comments
 (0)