Skip to content

Commit 6d39517

Browse files
committed
add removed test
1 parent 4a3e136 commit 6d39517

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

pkg/apis/dos/validation/dos_test.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,97 @@ func TestValidateAppProtectDosAccessLogDest(t *testing.T) {
214214
}
215215
}
216216

217+
func TestValidateAppProtectDosLogConf(t *testing.T) {
218+
t.Parallel()
219+
tests := []struct {
220+
logConf *unstructured.Unstructured
221+
expectErr bool
222+
expectWarn bool
223+
msg string
224+
}{
225+
{
226+
logConf: &unstructured.Unstructured{
227+
Object: map[string]interface{}{
228+
"spec": map[string]interface{}{
229+
"filter": map[string]interface{}{},
230+
},
231+
},
232+
},
233+
expectErr: false,
234+
expectWarn: false,
235+
msg: "valid log conf",
236+
},
237+
{
238+
logConf: &unstructured.Unstructured{
239+
Object: map[string]interface{}{
240+
"spec": map[string]interface{}{},
241+
},
242+
},
243+
expectErr: true,
244+
expectWarn: false,
245+
msg: "invalid log conf with no filter field",
246+
},
247+
{
248+
logConf: &unstructured.Unstructured{
249+
Object: map[string]interface{}{
250+
"something": map[string]interface{}{
251+
"filter": map[string]interface{}{},
252+
},
253+
},
254+
},
255+
expectErr: true,
256+
expectWarn: false,
257+
msg: "invalid log conf with no spec field",
258+
},
259+
{
260+
logConf: &unstructured.Unstructured{
261+
Object: map[string]interface{}{
262+
"spec": map[string]interface{}{
263+
"content": map[string]interface{}{
264+
"format": "user-defined",
265+
},
266+
"filter": map[string]interface{}{},
267+
},
268+
},
269+
},
270+
expectErr: false,
271+
expectWarn: true,
272+
msg: "Support only splunk format",
273+
},
274+
{
275+
logConf: &unstructured.Unstructured{
276+
Object: map[string]interface{}{
277+
"spec": map[string]interface{}{
278+
"filter": map[string]interface{}{},
279+
"content": map[string]interface{}{
280+
"format": "user-defined",
281+
},
282+
},
283+
},
284+
},
285+
expectErr: false,
286+
expectWarn: true,
287+
msg: "valid log conf with warning filter field",
288+
},
289+
}
290+
291+
for _, test := range tests {
292+
warn, err := ValidateAppProtectDosLogConf(test.logConf)
293+
if test.expectErr && err == nil {
294+
t.Errorf("validateAppProtectDosLogConf() returned no error for the case of %s", test.msg)
295+
}
296+
if !test.expectErr && err != nil {
297+
t.Errorf("validateAppProtectDosLogConf() returned unexpected error %v for the case of %s", err, test.msg)
298+
}
299+
if test.expectWarn && warn == "" {
300+
t.Errorf("validateAppProtectDosLogConf() returned no warning for the case of %s", test.msg)
301+
}
302+
if !test.expectWarn && warn != "" {
303+
t.Errorf("validateAppProtectDosLogConf() returned unexpected warning: %s, for the case of %s", warn, test.msg)
304+
}
305+
}
306+
}
307+
217308
func TestValidateAppProtectDosPolicy(t *testing.T) {
218309
t.Parallel()
219310
tests := []struct {

0 commit comments

Comments
 (0)