@@ -666,6 +666,42 @@ func TestBoxcutter_Apply(t *testing.T) {
666666 assert .Equal (t , "test-ext-1" , revList .Items [0 ].Name )
667667 },
668668 },
669+ {
670+ name : "adopts matching migration revision without creating a duplicate" ,
671+ mockBuilder : func (t * testing.T ) applier.ClusterObjectSetGenerator {
672+ ctrl := gomock .NewController (t )
673+ return mockapplier .NewMockClusterObjectSetGenerator (ctrl )
674+ },
675+ existingObjs : []client.Object {
676+ & ocv1.ClusterObjectSet {
677+ ObjectMeta : metav1.ObjectMeta {
678+ Name : "test-ext-1" ,
679+ Labels : map [string ]string {labels .OwnerNameKey : ext .Name },
680+ Annotations : map [string ]string {
681+ labels .MigratedFromSubscriptionKey : "test-namespace/test-subscription" ,
682+ labels .PackageNameKey : "test-package" ,
683+ labels .BundleNameKey : "test-package.v1.0.0" ,
684+ labels .BundleVersionKey : "1.0.0" ,
685+ labels .BundleReferenceKey : "registry.example/test-package@sha256:123" ,
686+ },
687+ },
688+ Spec : ocv1.ClusterObjectSetSpec {Revision : 1 },
689+ Status : ocv1.ClusterObjectSetStatus {Conditions : []metav1.Condition {{
690+ Type : ocv1 .ClusterObjectSetTypeSucceeded ,
691+ Status : metav1 .ConditionTrue ,
692+ }}},
693+ },
694+ },
695+ validate : func (t * testing.T , c client.Client ) {
696+ revList := & ocv1.ClusterObjectSetList {}
697+ require .NoError (t , c .List (t .Context (), revList , client.MatchingLabels {labels .OwnerNameKey : ext .Name }))
698+ require .Len (t , revList .Items , 1 )
699+ assert .Equal (t , "test-ext-1" , revList .Items [0 ].Name )
700+ require .Len (t , revList .Items [0 ].OwnerReferences , 1 )
701+ assert .Equal (t , ext .Name , revList .Items [0 ].OwnerReferences [0 ].Name )
702+ assert .Equal (t , ext .UID , revList .Items [0 ].OwnerReferences [0 ].UID )
703+ },
704+ },
669705 {
670706 name : "new revision created when objects in new revision are different" ,
671707 mockBuilder : func (t * testing.T ) applier.ClusterObjectSetGenerator {
@@ -1087,6 +1123,13 @@ func TestBoxcutter_Apply(t *testing.T) {
10871123 labels .BundleVersionKey : "1.0.1" ,
10881124 labels .PackageNameKey : "test-package" ,
10891125 }
1126+ } else if tc .name == "adopts matching migration revision without creating a duplicate" {
1127+ revisionAnnotations = map [string ]string {
1128+ labels .PackageNameKey : "test-package" ,
1129+ labels .BundleNameKey : "test-package.v1.0.0" ,
1130+ labels .BundleVersionKey : "1.0.0" ,
1131+ labels .BundleReferenceKey : "registry.example/test-package@sha256:123" ,
1132+ }
10901133 }
10911134 completed , status , err := boxcutter .Apply (t .Context (), testFS , ext , nil , revisionAnnotations )
10921135
0 commit comments