@@ -403,6 +403,42 @@ func TestHelmLint(t *testing.T) {
403403 }
404404}
405405
406+ func TestImageCertifyKubeVersionConstraints (t * testing.T ) {
407+ specificKubeVersion := "v1.21.0"
408+ tests := []struct {
409+ description string
410+ uri string
411+ optionalKubeVersionString * string
412+ outputIsValidFunc func (s string ) bool
413+ }{
414+ {
415+ description : "KubeVersion mismatch between default and chart should fail to run image checks" ,
416+ uri : "chart-0.1.0-v3.mocked-kubeversion-constraint-mismatch.tgz" ,
417+ outputIsValidFunc : func (s string ) bool {
418+ return strings .Contains (s , ImageCertifyFailed ) && strings .Contains (s , "which is incompatible with Kubernetes" )
419+ },
420+ },
421+ {
422+ description : "KubeVersion should align when --set is used to set a kubeversion" ,
423+ uri : "chart-0.1.0-v3.mocked-kubeversion-constraint-mismatch.tgz" ,
424+ outputIsValidFunc : func (s string ) bool {
425+ return strings .Contains (s , ImageCertified )
426+ },
427+ optionalKubeVersionString : & specificKubeVersion ,
428+ },
429+ }
430+
431+ for _ , test := range tests {
432+ v := viper .New ()
433+ if test .optionalKubeVersionString != nil {
434+ v .Set ("kube-version" , * test .optionalKubeVersionString )
435+ }
436+ // error is ignored because this fn never returns an error.
437+ result , _ := ImagesAreCertified_V1_1 (& CheckOptions {URI : test .uri , ViperConfig : v , HelmEnvSettings : cli .New ()})
438+ require .True (t , test .outputIsValidFunc (result .Reason ), test .description )
439+ }
440+ }
441+
406442func TestImageCertify (t * testing.T ) {
407443 checkImages (t )
408444}
@@ -415,6 +451,7 @@ func checkImages(t *testing.T) {
415451 numErrors int
416452 numPasses int
417453 numSkips int
454+ numFailures int
418455 }{
419456 {
420457 description : "chart-0.1.0-v3.valid.tgz check images passes" ,
@@ -516,6 +553,13 @@ func checkImages(t *testing.T) {
516553 }
517554 require .False (t , strings .Contains (r .Reason , ImageCertifySkipped ))
518555 }
556+ if tc .numErrors > 0 {
557+ for range tc .numErrors {
558+ require .Contains (t , r .Reason , ImageCertifyFailed )
559+ r .Reason = strings .Replace (r .Reason , ImageCertifyFailed , "_replaced_" , 1 )
560+ }
561+ require .False (t , strings .Contains (r .Reason , ImageCertifyFailed ))
562+ }
519563 })
520564 }
521565}
0 commit comments