@@ -15,67 +15,78 @@ import (
1515func TestValidateCRD (t * testing.T ) {
1616 var table = []struct {
1717 description string
18- directory string
18+ filePath string
1919 version string
2020 hasError bool
2121 errString string
2222 }{
2323 {
24- description : "registryv1 bundle/valid crd " ,
25- directory : "./testdata/v1beta1.crd.yaml" ,
24+ description : "registryv1 bundle/valid v1beta1 CRD " ,
25+ filePath : "./testdata/v1beta1.crd.yaml" ,
2626 version : "v1beta1" ,
2727 hasError : false ,
2828 errString : "" ,
2929 },
3030 {
31- description : "registryv1 bundle/ invalid crd " ,
32- directory : "./testdata/duplicateVersions.crd.yaml" ,
31+ description : "registryv1 bundle invalid v1beta1 CRD duplicate version " ,
32+ filePath : "./testdata/duplicateVersions.crd.yaml" ,
3333 version : "v1beta1" ,
3434 hasError : true ,
3535 errString : "must contain unique version names" ,
3636 },
3737 {
38- description : "registryv1 bundle/invalid crd " ,
39- directory : "./testdata/v1.crd.yaml" ,
38+ description : "registryv1 bundle/valid v1 CRD " ,
39+ filePath : "./testdata/v1.crd.yaml" ,
4040 version : "v1" ,
4141 hasError : false ,
4242 errString : "" ,
4343 },
4444 {
45- description : "registryv1 bundle/ invalid crd " ,
46- directory : "./testdata/deprecatedVersion.crd.yaml" ,
45+ description : "registryv1 bundle invalid v1 CRD deprecated .spec.version field " ,
46+ filePath : "./testdata/deprecatedVersion.crd.yaml" ,
4747 version : "v1" ,
4848 hasError : true ,
4949 errString : "must have exactly one version marked as storage version" ,
5050 },
51+ {
52+ description : "registryv1 bundle invalid CRD no conversionReviewVersions" ,
53+ filePath : "./testdata/noConversionReviewVersions.crd.yaml" ,
54+ version : "v1" ,
55+ hasError : true ,
56+ errString : "spec.conversion.conversionReviewVersions: Required value" ,
57+ },
5158 }
52-
5359 for _ , tt := range table {
54- b , err := ioutil .ReadFile (tt .directory )
60+ b , err := ioutil .ReadFile (tt .filePath )
5561 if err != nil {
56- t .Fatalf ("Error reading CRD path %s: %v" , tt .directory , err )
62+ t .Fatalf ("Error reading CRD path %s: %v" , tt .filePath , err )
5763 }
5864
5965 results := []errors.ManifestResult {}
6066 switch tt .version {
6167 case "v1" :
6268 crd := & v1.CustomResourceDefinition {}
6369 if err = yaml .Unmarshal (b , crd ); err != nil {
64- t .Fatalf ("Error unmarshalling CRD at path %s: %v" , tt .directory , err )
70+ t .Fatalf ("Error unmarshalling CRD at path %s: %v" , tt .filePath , err )
6571 }
6672 results = CRDValidator .Validate (crd )
6773 default :
6874 crd := & v1beta1.CustomResourceDefinition {}
6975 if err = yaml .Unmarshal (b , crd ); err != nil {
70- t .Fatalf ("Error unmarshalling CRD at path %s: %v" , tt .directory , err )
76+ t .Fatalf ("Error unmarshalling CRD at path %s: %v" , tt .filePath , err )
7177 }
7278 results = CRDValidator .Validate (crd )
7379 }
7480
7581 if len (results ) > 0 {
76- require .Equal (t , results [0 ].HasError (), tt .hasError )
7782 if results [0 ].HasError () {
78- require .Contains (t , results [0 ].Errors [0 ].Error (), tt .errString )
83+ if ! tt .hasError {
84+ t .Errorf ("%s: expected no errors, got: %+q" , tt .description , results [0 ].Errors )
85+ } else {
86+ require .Contains (t , results [0 ].Errors [0 ].Error (), tt .errString , tt .description )
87+ }
88+ } else if tt .hasError {
89+ t .Errorf ("%s: expected error %q, got none" , tt .description , tt .errString )
7990 }
8091 }
8192 }
0 commit comments