@@ -97,13 +97,14 @@ func TestLoadReader(t *testing.T) {
9797
9898func TestWalkMetasFS (t * testing.T ) {
9999 type spec struct {
100- name string
101- fsys fs.FS
102- assertion require.ErrorAssertionFunc
103- expectNumPackages int
104- expectNumChannels int
105- expectNumBundles int
106- expectNumOthers int
100+ name string
101+ fsys fs.FS
102+ assertion require.ErrorAssertionFunc
103+ expectNumPackages int
104+ expectNumChannels int
105+ expectNumBundles int
106+ expectNumDeprecations int
107+ expectNumOthers int
107108 }
108109 specs := []spec {
109110 {
@@ -122,19 +123,20 @@ func TestWalkMetasFS(t *testing.T) {
122123 assertion : require .Error ,
123124 },
124125 {
125- name : "Success/ValidDir" ,
126- fsys : validFS ,
127- assertion : require .NoError ,
128- expectNumPackages : 3 ,
129- expectNumChannels : 0 ,
130- expectNumBundles : 12 ,
131- expectNumOthers : 1 ,
126+ name : "Success/ValidDir" ,
127+ fsys : validFS ,
128+ assertion : require .NoError ,
129+ expectNumPackages : 3 ,
130+ expectNumChannels : 0 ,
131+ expectNumBundles : 12 ,
132+ expectNumDeprecations : 1 ,
133+ expectNumOthers : 1 ,
132134 },
133135 }
134136
135137 for _ , s := range specs {
136138 t .Run (s .name , func (t * testing.T ) {
137- numPackages , numChannels , numBundles , numOthers := 0 , 0 , 0 , 0
139+ numPackages , numChannels , numBundles , numDeprecations , numOthers := 0 , 0 , 0 , 0 , 0
138140 err := WalkMetasFS (s .fsys , func (path string , meta * Meta , err error ) error {
139141 if err != nil {
140142 return err
@@ -146,6 +148,8 @@ func TestWalkMetasFS(t *testing.T) {
146148 numChannels ++
147149 case SchemaBundle :
148150 numBundles ++
151+ case SchemaDeprecation :
152+ numDeprecations ++
149153 default :
150154 numOthers ++
151155 }
@@ -332,6 +336,18 @@ func TestLoadFS(t *testing.T) {
332336 Schema : "olm.bundle" ,
333337 },
334338 },
339+ Deprecations : []Deprecation {
340+ {
341+ Schema : "olm.catalog.deprecation" ,
342+ Package : "kiali" ,
343+ Name : "bobs-discount-name" ,
344+ Deprecations : []DeprecationEntry {
345+ {Schema : "olm.bundle" , Name : "kiali-operator.v1.68.0" , Message : json .RawMessage (`"kiali-operator.v1.68.0 is deprecated. Uninstall and install kiali-operator.v1.72.0 for support.\n"` )},
346+ {Schema : "olm.package" , Name : "kiali" , Message : json .RawMessage (`"package kiali is end of life. Please use 'kiali-new' package for support.\n"` )},
347+ {Schema : "olm.channel" , Name : "alpha" , Message : json .RawMessage (`"channel alpha is no longer supported. Please switch to channel 'stable'.\n"` )},
348+ },
349+ },
350+ },
335351 Others : []Meta {
336352 {Schema : "unexpected" , Package : "" , Blob : json .RawMessage (`{ "schema": "unexpected" }` )},
337353 },
@@ -881,6 +897,25 @@ present in the .indexignore file.`),
881897 unrecognizedSchema = & fstest.MapFile {
882898 Data : []byte (`{"schema":"olm.package"}{"schema":"unexpected"}{"schema":"olm.bundle"}` ),
883899 }
900+ deprecations = & fstest.MapFile {
901+ Data : []byte (`---
902+ schema: olm.catalog.deprecation
903+ package: kiali
904+ name: bobs-discount-name
905+ deprecations:
906+ - schema: olm.bundle
907+ name: kiali-operator.v1.68.0
908+ message: |
909+ kiali-operator.v1.68.0 is deprecated. Uninstall and install kiali-operator.v1.72.0 for support.
910+ - schema: olm.package
911+ name: kiali
912+ message: |
913+ package kiali is end of life. Please use 'kiali-new' package for support.
914+ - schema: olm.channel
915+ name: alpha
916+ message: |
917+ channel alpha is no longer supported. Please switch to channel 'stable'.` ),
918+ }
884919
885920 validFS = fstest.MapFS {
886921 ".indexignore" : indexIgnore ,
@@ -889,18 +924,19 @@ present in the .indexignore file.`),
889924 "etcdoperator.v0.6.1.clusterserviceversion.yaml" : etcdCSV ,
890925 "README.md" : readme ,
891926 "unrecognized-schema.json" : unrecognizedSchema ,
927+ "deprecations.yaml" : deprecations ,
892928 }
893929)
894930
931+ type EvaluationFunc func (* testing.T , * DeclarativeConfig )
932+
895933func TestLoadFile (t * testing.T ) {
896934 type spec struct {
897- name string
898- fsys fs.FS
899- path string
900- assertion require.ErrorAssertionFunc
901- expectNumPackages int
902- expectNumBundles int
903- expectNumOthers int
935+ name string
936+ fsys fs.FS
937+ path string
938+ assertion require.ErrorAssertionFunc
939+ expect EvaluationFunc
904940 }
905941 specs := []spec {
906942 {
@@ -944,22 +980,38 @@ func TestLoadFile(t *testing.T) {
944980 assertion : require .Error ,
945981 },
946982 {
947- name : "Success/UnrecognizedSchema" ,
948- fsys : validFS ,
949- path : "unrecognized-schema.json" ,
950- assertion : require .NoError ,
951- expectNumPackages : 1 ,
952- expectNumBundles : 1 ,
953- expectNumOthers : 1 ,
983+ name : "Success/UnrecognizedSchema" ,
984+ fsys : validFS ,
985+ path : "unrecognized-schema.json" ,
986+ assertion : require .NoError ,
987+ expect : func (t * testing.T , d * DeclarativeConfig ) {
988+ require .Equal (t , 1 , len (d .Packages ))
989+ require .Equal (t , 1 , len (d .Bundles ))
990+ require .Equal (t , 1 , len (d .Others ))
991+ },
954992 },
955993 {
956- name : "Success/ValidFile" ,
957- fsys : validFS ,
958- path : "etcd.yaml" ,
959- assertion : require .NoError ,
960- expectNumPackages : 1 ,
961- expectNumBundles : 6 ,
962- expectNumOthers : 0 ,
994+ name : "Success/ValidFile" ,
995+ fsys : validFS ,
996+ path : "etcd.yaml" ,
997+ assertion : require .NoError ,
998+ expect : func (t * testing.T , d * DeclarativeConfig ) {
999+ require .Equal (t , 1 , len (d .Packages ))
1000+ require .Equal (t , 6 , len (d .Bundles ))
1001+ require .Equal (t , 0 , len (d .Others ))
1002+ },
1003+ },
1004+ {
1005+ name : "Success/ValidFile/Deprecations" ,
1006+ fsys : validFS ,
1007+ path : "deprecations.yaml" ,
1008+ assertion : require .NoError ,
1009+ expect : func (t * testing.T , d * DeclarativeConfig ) {
1010+ require .Equal (t , 0 , len (d .Packages ))
1011+ require .Equal (t , 0 , len (d .Bundles ))
1012+ require .Equal (t , 0 , len (d .Others ))
1013+ require .Equal (t , 1 , len (d .Deprecations ))
1014+ },
9631015 },
9641016 }
9651017
@@ -969,9 +1021,7 @@ func TestLoadFile(t *testing.T) {
9691021 s .assertion (t , err )
9701022 if err == nil {
9711023 require .NotNil (t , cfg )
972- assert .Equal (t , len (cfg .Packages ), s .expectNumPackages , "unexpected package count" )
973- assert .Equal (t , len (cfg .Bundles ), s .expectNumBundles , "unexpected bundle count" )
974- assert .Equal (t , len (cfg .Others ), s .expectNumOthers , "unexpected others count" )
1024+ s .expect (t , cfg )
9751025 }
9761026 })
9771027 }
0 commit comments