@@ -911,6 +911,140 @@ func TestDeprecateBundle(t *testing.T) {
911
911
}
912
912
}
913
913
914
+ func TestAddAfterDeprecate (t * testing.T ) {
915
+ type args struct {
916
+ firstBundles []string
917
+ deprecatedBundles []string
918
+ secondBundles []string
919
+ }
920
+ type pkgChannel map [string ][]string
921
+ type expected struct {
922
+ err error
923
+ remainingBundles []string
924
+ deprecatedBundles []string
925
+ remainingPkgChannels pkgChannel
926
+ }
927
+ tests := []struct {
928
+ description string
929
+ args args
930
+ expected expected
931
+ }{
932
+ {
933
+ description : "SimpleAdd" ,
934
+ args : args {
935
+ firstBundles : []string {
936
+ "prometheus.0.14.0" ,
937
+ "prometheus.0.15.0" ,
938
+ },
939
+ deprecatedBundles : []string {
940
+ "quay.io/test/prometheus.0.15.0" ,
941
+ },
942
+ secondBundles : []string {
943
+ "prometheus.0.22.2" ,
944
+ },
945
+ },
946
+ expected : expected {
947
+ err : nil ,
948
+ remainingBundles : []string {
949
+ "quay.io/test/prometheus.0.15.0/preview" ,
950
+ "quay.io/test/prometheus.0.15.0/stable" ,
951
+ "quay.io/test/prometheus.0.22.2/preview" ,
952
+ },
953
+ deprecatedBundles : []string {
954
+ "quay.io/test/prometheus.0.15.0/preview" ,
955
+ "quay.io/test/prometheus.0.15.0/stable" ,
956
+ },
957
+ remainingPkgChannels : pkgChannel {
958
+ "prometheus" : []string {
959
+ "preview" ,
960
+ "stable" ,
961
+ },
962
+ },
963
+ },
964
+ },
965
+ }
966
+
967
+ for _ , tt := range tests {
968
+ t .Run (tt .description , func (t * testing.T ) {
969
+ logrus .SetLevel (logrus .DebugLevel )
970
+ db , cleanup := CreateTestDb (t )
971
+ defer cleanup ()
972
+
973
+ load , err := sqlite .NewSQLLiteLoader (db , sqlite .WithEnableAlpha (true ))
974
+ require .NoError (t , err )
975
+ err = load .Migrate (context .TODO ())
976
+ require .NoError (t , err )
977
+ query := sqlite .NewSQLLiteQuerierFromDb (db )
978
+
979
+ graphLoader , err := sqlite .NewSQLGraphLoaderFromDB (db )
980
+ require .NoError (t , err )
981
+
982
+ populate := func (names []string ) error {
983
+ refMap := make (map [image.Reference ]string , 0 )
984
+ for _ , name := range names {
985
+ refMap [image .SimpleReference ("quay.io/test/" + name )] = "../../bundles/" + name
986
+ }
987
+ return registry .NewDirectoryPopulator (
988
+ load ,
989
+ graphLoader ,
990
+ query ,
991
+ refMap ,
992
+ make (map [string ]map [image.Reference ]string , 0 ), false ).Populate (registry .ReplacesMode )
993
+ }
994
+ // Initialize index with some bundles
995
+ require .NoError (t , populate (tt .args .firstBundles ))
996
+
997
+ deprecator := sqlite .NewSQLDeprecatorForBundles (load , tt .args .deprecatedBundles )
998
+ err = deprecator .Deprecate ()
999
+ require .Equal (t , tt .expected .err , err )
1000
+
1001
+ require .NoError (t , populate (tt .args .secondBundles ))
1002
+
1003
+ // Ensure remaining bundlePaths in db match
1004
+ bundles , err := query .ListBundles (context .Background ())
1005
+ require .NoError (t , err )
1006
+ var bundlePaths []string
1007
+ for _ , bundle := range bundles {
1008
+ bundlePaths = append (bundlePaths , strings .Join ([]string {bundle .BundlePath , bundle .ChannelName }, "/" ))
1009
+ }
1010
+ require .ElementsMatch (t , tt .expected .remainingBundles , bundlePaths )
1011
+
1012
+ // Ensure deprecated bundles match
1013
+ var deprecatedBundles []string
1014
+ deprecatedProperty , err := json .Marshal (registry.DeprecatedProperty {})
1015
+ require .NoError (t , err )
1016
+ for _ , bundle := range bundles {
1017
+ for _ , prop := range bundle .Properties {
1018
+ if prop .Type == registry .DeprecatedType && prop .Value == string (deprecatedProperty ) {
1019
+ deprecatedBundles = append (deprecatedBundles , strings .Join ([]string {bundle .BundlePath , bundle .ChannelName }, "/" ))
1020
+ }
1021
+ }
1022
+ }
1023
+
1024
+ require .ElementsMatch (t , tt .expected .deprecatedBundles , deprecatedBundles )
1025
+
1026
+ // Ensure remaining channels match
1027
+ packages , err := query .ListPackages (context .Background ())
1028
+ require .NoError (t , err )
1029
+
1030
+ for _ , pkg := range packages {
1031
+ channelEntries , err := query .GetChannelEntriesFromPackage (context .Background (), pkg )
1032
+ require .NoError (t , err )
1033
+
1034
+ uniqueChannels := make (map [string ]struct {})
1035
+ var channels []string
1036
+ for _ , ch := range channelEntries {
1037
+ uniqueChannels [ch .ChannelName ] = struct {}{}
1038
+ }
1039
+ for k := range uniqueChannels {
1040
+ channels = append (channels , k )
1041
+ }
1042
+ require .ElementsMatch (t , tt .expected .remainingPkgChannels [pkg ], channels )
1043
+ }
1044
+ })
1045
+ }
1046
+ }
1047
+
914
1048
func TestOverwrite (t * testing.T ) {
915
1049
type args struct {
916
1050
firstAdd map [image.Reference ]string
0 commit comments