@@ -97,13 +97,14 @@ func TestLoadReader(t *testing.T) {
97
97
98
98
func TestWalkMetasFS (t * testing.T ) {
99
99
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
107
108
}
108
109
specs := []spec {
109
110
{
@@ -122,19 +123,20 @@ func TestWalkMetasFS(t *testing.T) {
122
123
assertion : require .Error ,
123
124
},
124
125
{
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 ,
132
134
},
133
135
}
134
136
135
137
for _ , s := range specs {
136
138
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
138
140
err := WalkMetasFS (s .fsys , func (path string , meta * Meta , err error ) error {
139
141
if err != nil {
140
142
return err
@@ -146,6 +148,8 @@ func TestWalkMetasFS(t *testing.T) {
146
148
numChannels ++
147
149
case SchemaBundle :
148
150
numBundles ++
151
+ case SchemaDeprecation :
152
+ numDeprecations ++
149
153
default :
150
154
numOthers ++
151
155
}
@@ -332,6 +336,18 @@ func TestLoadFS(t *testing.T) {
332
336
Schema : "olm.bundle" ,
333
337
},
334
338
},
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
+ },
335
351
Others : []Meta {
336
352
{Schema : "unexpected" , Package : "" , Blob : json .RawMessage (`{ "schema": "unexpected" }` )},
337
353
},
@@ -881,6 +897,25 @@ present in the .indexignore file.`),
881
897
unrecognizedSchema = & fstest.MapFile {
882
898
Data : []byte (`{"schema":"olm.package"}{"schema":"unexpected"}{"schema":"olm.bundle"}` ),
883
899
}
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
+ }
884
919
885
920
validFS = fstest.MapFS {
886
921
".indexignore" : indexIgnore ,
@@ -889,18 +924,19 @@ present in the .indexignore file.`),
889
924
"etcdoperator.v0.6.1.clusterserviceversion.yaml" : etcdCSV ,
890
925
"README.md" : readme ,
891
926
"unrecognized-schema.json" : unrecognizedSchema ,
927
+ "deprecations.yaml" : deprecations ,
892
928
}
893
929
)
894
930
931
+ type EvaluationFunc func (* testing.T , * DeclarativeConfig )
932
+
895
933
func TestLoadFile (t * testing.T ) {
896
934
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
904
940
}
905
941
specs := []spec {
906
942
{
@@ -944,22 +980,38 @@ func TestLoadFile(t *testing.T) {
944
980
assertion : require .Error ,
945
981
},
946
982
{
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
+ },
954
992
},
955
993
{
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
+ },
963
1015
},
964
1016
}
965
1017
@@ -969,9 +1021,7 @@ func TestLoadFile(t *testing.T) {
969
1021
s .assertion (t , err )
970
1022
if err == nil {
971
1023
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 )
975
1025
}
976
1026
})
977
1027
}
0 commit comments