Skip to content

Commit 760d7f6

Browse files
committed
test helper; check interface compliance
1 parent 8b0668f commit 760d7f6

File tree

8 files changed

+32
-66
lines changed

8 files changed

+32
-66
lines changed

pkg/acquisition/appsec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var (
1111
_ DataSource = (*appsecacquisition.Source)(nil)
1212
_ Tailer = (*appsecacquisition.Source)(nil)
1313
_ MetricsProvider = (*appsecacquisition.Source)(nil)
14+
_ HubAware = (*appsecacquisition.Source)(nil)
1415
)
1516

1617
//nolint:gochecknoinits

pkg/acquisition/modules/appsec/appsec_hooks_test.go

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,8 @@ func TestAppsecOnMatchHooks(t *testing.T) {
407407
},
408408
},
409409
}
410-
for _, test := range tests {
411-
t.Run(test.name, func(t *testing.T) {
412-
loadAppSecEngine(test, t)
413-
})
414-
}
410+
411+
runTests(t, tests)
415412
}
416413

417414
func TestAppsecPreEvalHooks(t *testing.T) {
@@ -824,11 +821,7 @@ func TestAppsecPreEvalHooks(t *testing.T) {
824821
},
825822
}
826823

827-
for _, test := range tests {
828-
t.Run(test.name, func(t *testing.T) {
829-
loadAppSecEngine(test, t)
830-
})
831-
}
824+
runTests(t, tests)
832825
}
833826

834827
func TestAppsecRemediationConfigHooks(t *testing.T) {
@@ -917,11 +910,7 @@ func TestAppsecRemediationConfigHooks(t *testing.T) {
917910
},
918911
}
919912

920-
for _, test := range tests {
921-
t.Run(test.name, func(t *testing.T) {
922-
loadAppSecEngine(test, t)
923-
})
924-
}
913+
runTests(t, tests)
925914
}
926915

927916
func TestOnMatchRemediationHooks(t *testing.T) {
@@ -1090,9 +1079,6 @@ func TestOnMatchRemediationHooks(t *testing.T) {
10901079
},
10911080
},
10921081
}
1093-
for _, test := range tests {
1094-
t.Run(test.name, func(t *testing.T) {
1095-
loadAppSecEngine(test, t)
1096-
})
1097-
}
1082+
1083+
runTests(t, tests)
10981084
}

pkg/acquisition/modules/appsec/appsec_lnx_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ func TestAppsecRuleTransformsOthers(t *testing.T) {
6969
},
7070
},
7171
}
72-
for _, test := range tests {
73-
t.Run(test.name, func(t *testing.T) {
74-
loadAppSecEngine(test, t)
75-
})
76-
}
72+
73+
runTests(t, tests)
7774
}

pkg/acquisition/modules/appsec/appsec_remediation_test.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,8 @@ func TestAppsecDefaultPassRemediation(t *testing.T) {
149149
},
150150
},
151151
}
152-
for _, test := range tests {
153-
t.Run(test.name, func(t *testing.T) {
154-
loadAppSecEngine(test, t)
155-
})
156-
}
152+
153+
runTests(t, tests)
157154
}
158155

159156
func TestAppsecDefaultRemediation(t *testing.T) {
@@ -322,9 +319,5 @@ func TestAppsecDefaultRemediation(t *testing.T) {
322319
},
323320
}
324321

325-
for _, test := range tests {
326-
t.Run(test.name, func(t *testing.T) {
327-
loadAppSecEngine(test, t)
328-
})
329-
}
322+
runTests(t, tests)
330323
}

pkg/acquisition/modules/appsec/appsec_rules_test.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,7 @@ toto
418418
},
419419
}
420420

421-
for _, test := range tests {
422-
t.Run(test.name, func(t *testing.T) {
423-
loadAppSecEngine(test, t)
424-
})
425-
}
421+
runTests(t, tests)
426422
}
427423

428424
func TestAppsecRuleTransforms(t *testing.T) {
@@ -633,11 +629,8 @@ func TestAppsecRuleTransforms(t *testing.T) {
633629
},
634630
},
635631
}
636-
for _, test := range tests {
637-
t.Run(test.name, func(t *testing.T) {
638-
loadAppSecEngine(test, t)
639-
})
640-
}
632+
633+
runTests(t, tests)
641634
}
642635

643636
func TestAppsecRuleZones(t *testing.T) {
@@ -947,9 +940,6 @@ func TestAppsecRuleZones(t *testing.T) {
947940
},
948941
},
949942
}
950-
for _, test := range tests {
951-
t.Run(test.name, func(t *testing.T) {
952-
loadAppSecEngine(test, t)
953-
})
954-
}
943+
944+
runTests(t, tests)
955945
}

pkg/acquisition/modules/appsec/appsec_runner_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,8 @@ func TestAppsecConflictRuleLoad(t *testing.T) {
6666
},
6767
},
6868
}
69-
for _, test := range tests {
70-
t.Run(test.name, func(t *testing.T) {
71-
loadAppSecEngine(test, t)
72-
})
73-
}
69+
70+
runTests(t, tests)
7471
}
7572

7673
func TestAppsecRuleLoad(t *testing.T) {
@@ -200,9 +197,6 @@ func TestAppsecRuleLoad(t *testing.T) {
200197
},
201198
},
202199
}
203-
for _, test := range tests {
204-
t.Run(test.name, func(t *testing.T) {
205-
loadAppSecEngine(test, t)
206-
})
207-
}
200+
201+
runTests(t, tests)
208202
}

pkg/acquisition/modules/appsec/appsec_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ func setupWithPrefix(urlPrefix string) (*http.ServeMux, string, func()) {
5959
return mux, server.URL, server.Close
6060
}
6161

62-
func loadAppSecEngine(test appsecRuleTest, t *testing.T) {
62+
func runTests(t *testing.T, tests []appsecRuleTest) {
63+
for _, test := range tests {
64+
t.Run(test.name, func(t *testing.T) {
65+
testAppSecEngine(t, test)
66+
})
67+
}
68+
}
69+
70+
func testAppSecEngine(t *testing.T, test appsecRuleTest) {
6371
if testing.Verbose() {
6472
log.SetLevel(log.TraceLevel)
6573
} else {

pkg/acquisition/modules/appsec/appsec_win_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ func TestAppsecRuleTransformsWindows(t *testing.T) {
3737
// },
3838
// },
3939
}
40-
for _, test := range tests {
41-
t.Run(test.name, func(t *testing.T) {
42-
loadAppSecEngine(test, t)
43-
})
44-
}
40+
41+
runTests(t, tests)
4542
}

0 commit comments

Comments
 (0)