@@ -63,7 +63,7 @@ func TestValidateDosProtectedResource(t *testing.T) {
6363 DosAccessLogDest : "bad&$%^logdest" ,
6464 },
6565 },
66- expectErr : "error validating DosProtectedResource: invalid field: dosAccessLogDest err: invalid host : bad&$%^logdest, must follow format: <ip-address | localhost | dns name>:<port> or stderr" ,
66+ expectErr : "error validating DosProtectedResource: invalid field: dosAccessLogDest err: invalid log destination : bad&$%^logdest, must follow format: <ip-address | localhost | dns name>:<port> or stderr" ,
6767 msg : "invalid DosAccessLogDest specified" ,
6868 },
6969 {
@@ -105,7 +105,7 @@ func TestValidateDosProtectedResource(t *testing.T) {
105105 DosSecurityLog : & v1beta1.DosSecurityLog {},
106106 },
107107 },
108- expectErr : "error validating DosProtectedResource: invalid field: dosSecurityLog/dosLogDest err: error parsing host: empty host , must follow format: <ip-address | localhost | dns name>:<port> or stderr" ,
108+ expectErr : "error validating DosProtectedResource: invalid field: dosSecurityLog/dosLogDest err: invalid log destination: , must follow format: <ip-address | localhost | dns name>:<port> or stderr" ,
109109 msg : "empty DosSecurityLog specified" ,
110110 },
111111 {
@@ -159,7 +159,6 @@ func TestValidateDosProtectedResource(t *testing.T) {
159159 msg : "DosSecurityLog with valid apDosLogConf" ,
160160 },
161161 }
162-
163162 for _ , test := range tests {
164163 err := ValidateDosProtectedResource (test .protected )
165164 if err != nil {
@@ -191,9 +190,9 @@ func TestValidateAppProtectDosAccessLogDest(t *testing.T) {
191190
192191 // Negative test cases item, expected error message
193192 negDstAntns := [][]string {
194- {"NotValid" , "invalid host : NotValid, must follow format: <ip-address | localhost | dns name>:<port> or stderr" },
195- {"cluster.local" , "invalid host : cluster.local, must follow format: <ip-address | localhost | dns name>:<port> or stderr" },
196- {"-cluster.local:514" , "invalid host : -cluster.local:514, must follow format: <ip-address | localhost | dns name>:<port> or stderr" },
193+ {"NotValid" , "invalid log destination : NotValid, must follow format: <ip-address | localhost | dns name>:<port> or stderr" },
194+ {"cluster.local" , "invalid log destination : cluster.local, must follow format: <ip-address | localhost | dns name>:<port> or stderr" },
195+ {"-cluster.local:514" , "invalid log destination : -cluster.local:514, must follow format: <ip-address | localhost | dns name>:<port> or stderr" },
197196 {"10.10.1.1:99999" , "not a valid port number" },
198197 }
199198
@@ -203,7 +202,6 @@ func TestValidateAppProtectDosAccessLogDest(t *testing.T) {
203202 t .Errorf ("expected nil, got %v" , err )
204203 }
205204 }
206-
207205 for _ , nTCase := range negDstAntns {
208206 err := validateAppProtectDosLogDest (nTCase [0 ])
209207 if err == nil {
@@ -216,97 +214,6 @@ func TestValidateAppProtectDosAccessLogDest(t *testing.T) {
216214 }
217215}
218216
219- func TestValidateAppProtectDosLogConf (t * testing.T ) {
220- t .Parallel ()
221- tests := []struct {
222- logConf * unstructured.Unstructured
223- expectErr bool
224- expectWarn bool
225- msg string
226- }{
227- {
228- logConf : & unstructured.Unstructured {
229- Object : map [string ]interface {}{
230- "spec" : map [string ]interface {}{
231- "filter" : map [string ]interface {}{},
232- },
233- },
234- },
235- expectErr : false ,
236- expectWarn : false ,
237- msg : "valid log conf" ,
238- },
239- {
240- logConf : & unstructured.Unstructured {
241- Object : map [string ]interface {}{
242- "spec" : map [string ]interface {}{},
243- },
244- },
245- expectErr : true ,
246- expectWarn : false ,
247- msg : "invalid log conf with no filter field" ,
248- },
249- {
250- logConf : & unstructured.Unstructured {
251- Object : map [string ]interface {}{
252- "something" : map [string ]interface {}{
253- "filter" : map [string ]interface {}{},
254- },
255- },
256- },
257- expectErr : true ,
258- expectWarn : false ,
259- msg : "invalid log conf with no spec field" ,
260- },
261- {
262- logConf : & unstructured.Unstructured {
263- Object : map [string ]interface {}{
264- "spec" : map [string ]interface {}{
265- "content" : map [string ]interface {}{
266- "format" : "user-defined" ,
267- },
268- "filter" : map [string ]interface {}{},
269- },
270- },
271- },
272- expectErr : false ,
273- expectWarn : true ,
274- msg : "Support only splunk format" ,
275- },
276- {
277- logConf : & unstructured.Unstructured {
278- Object : map [string ]interface {}{
279- "spec" : map [string ]interface {}{
280- "filter" : map [string ]interface {}{},
281- "content" : map [string ]interface {}{
282- "format" : "user-defined" ,
283- },
284- },
285- },
286- },
287- expectErr : false ,
288- expectWarn : true ,
289- msg : "valid log conf with warning filter field" ,
290- },
291- }
292-
293- for _ , test := range tests {
294- warn , err := ValidateAppProtectDosLogConf (test .logConf )
295- if test .expectErr && err == nil {
296- t .Errorf ("validateAppProtectDosLogConf() returned no error for the case of %s" , test .msg )
297- }
298- if ! test .expectErr && err != nil {
299- t .Errorf ("validateAppProtectDosLogConf() returned unexpected error %v for the case of %s" , err , test .msg )
300- }
301- if test .expectWarn && warn == "" {
302- t .Errorf ("validateAppProtectDosLogConf() returned no warning for the case of %s" , test .msg )
303- }
304- if ! test .expectWarn && warn != "" {
305- t .Errorf ("validateAppProtectDosLogConf() returned unexpected warning: %s, for the case of %s" , warn , test .msg )
306- }
307- }
308- }
309-
310217func TestValidateAppProtectDosPolicy (t * testing.T ) {
311218 t .Parallel ()
312219 tests := []struct {
0 commit comments