@@ -32,7 +32,8 @@ func TestValidate(t *testing.T) {
3232 schemaRegistry2 []byte
3333 ignoreMissingSchema bool
3434 strict bool
35- expect Status
35+ expectStatus Status
36+ expectErrors []ValidationError
3637 }{
3738 {
3839 "valid resource" ,
@@ -67,6 +68,7 @@ lastName: bar
6768 false ,
6869 false ,
6970 Valid ,
71+ []ValidationError {},
7072 },
7173 {
7274 "invalid resource" ,
@@ -101,6 +103,12 @@ lastName: bar
101103 false ,
102104 false ,
103105 Invalid ,
106+ []ValidationError {
107+ {
108+ Path : "/firstName" ,
109+ Msg : "expected number, but got string" ,
110+ },
111+ },
104112 },
105113 {
106114 "missing required field" ,
@@ -134,6 +142,12 @@ firstName: foo
134142 false ,
135143 false ,
136144 Invalid ,
145+ []ValidationError {
146+ {
147+ Path : "" ,
148+ Msg : "missing properties: 'lastName'" ,
149+ },
150+ },
137151 },
138152 {
139153 "key \" firstName\" already set in map" ,
@@ -160,6 +174,7 @@ firstName: bar
160174 false ,
161175 true ,
162176 Error ,
177+ []ValidationError {},
163178 },
164179 {
165180 "key firstname already set in map in non-strict mode" ,
@@ -186,6 +201,7 @@ firstName: bar
186201 false ,
187202 false ,
188203 Valid ,
204+ []ValidationError {},
189205 },
190206 {
191207 "resource has invalid yaml" ,
@@ -223,6 +239,7 @@ lastName: bar
223239 false ,
224240 false ,
225241 Error ,
242+ []ValidationError {},
226243 },
227244 {
228245 "missing schema in 1st registry" ,
@@ -260,6 +277,7 @@ lastName: bar
260277 false ,
261278 false ,
262279 Valid ,
280+ []ValidationError {},
263281 },
264282 {
265283 "non-json response in 1st registry" ,
@@ -297,6 +315,7 @@ lastName: bar
297315 false ,
298316 false ,
299317 Valid ,
318+ []ValidationError {},
300319 },
301320 {
302321 "missing schema in both registries, ignore missing" ,
@@ -311,6 +330,7 @@ lastName: bar
311330 true ,
312331 false ,
313332 Skipped ,
333+ []ValidationError {},
314334 },
315335 {
316336 "missing schema in both registries, do not ignore missing" ,
@@ -325,6 +345,7 @@ lastName: bar
325345 false ,
326346 false ,
327347 Error ,
348+ []ValidationError {},
328349 },
329350 {
330351 "non-json response in both registries, ignore missing" ,
@@ -339,6 +360,7 @@ lastName: bar
339360 true ,
340361 false ,
341362 Skipped ,
363+ []ValidationError {},
342364 },
343365 {
344366 "non-json response in both registries, do not ignore missing" ,
@@ -353,6 +375,7 @@ lastName: bar
353375 false ,
354376 false ,
355377 Error ,
378+ []ValidationError {},
356379 },
357380 } {
358381 val := v {
@@ -373,11 +396,21 @@ lastName: bar
373396 }),
374397 },
375398 }
376- if got := val .ValidateResource (resource.Resource {Bytes : testCase .rawResource }); got .Status != testCase .expect {
399+ got := val .ValidateResource (resource.Resource {Bytes : testCase .rawResource })
400+ if got .Status != testCase .expectStatus {
377401 if got .Err != nil {
378- t .Errorf ("Test '%s' - expected %d, got %d: %s" , testCase .name , testCase .expect , got .Status , got .Err .Error ())
402+ t .Errorf ("Test '%s' - expected %d, got %d: %s" , testCase .name , testCase .expectStatus , got .Status , got .Err .Error ())
379403 } else {
380- t .Errorf ("%d - expected %d, got %d" , i , testCase .expect , got .Status )
404+ t .Errorf ("Test '%s'- %d - expected %d, got %d" , testCase .name , i , testCase .expectStatus , got .Status )
405+ }
406+ }
407+
408+ if len (got .ValidationErrors ) != len (testCase .expectErrors ) {
409+ t .Errorf ("Test '%s': expected ValidationErrors: %+v, got: % v" , testCase .name , testCase .expectErrors , got .ValidationErrors )
410+ }
411+ for i , _ := range testCase .expectErrors {
412+ if testCase .expectErrors [i ] != got .ValidationErrors [i ] {
413+ t .Errorf ("Test '%s': expected ValidationErrors: %+v, got: % v" , testCase .name , testCase .expectErrors , got .ValidationErrors )
381414 }
382415 }
383416 }
0 commit comments