Skip to content

Commit e60836a

Browse files
committed
test(migration): cover shared migration store
Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
1 parent d420550 commit e60836a

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

images/virtualization-artifact/pkg/migration/store/store_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,51 @@ var _ = Describe("Migration store", func() {
7575
Expect(fakeClient.Get(context.Background(), types.NamespacedName{Name: ConfigMapName, Namespace: Namespace}, updatedCM)).To(Succeed())
7676
Expect(updatedCM.Data).To(HaveKeyWithValue("test-migration", completedAt))
7777
})
78+
79+
It("should return false when shared ConfigMap exists without migration key", func() {
80+
cm := &corev1.ConfigMap{
81+
ObjectMeta: metav1.ObjectMeta{Name: ConfigMapName, Namespace: Namespace},
82+
Data: map[string]string{"other-migration": "2026-04-29T10:25:06Z"},
83+
}
84+
fakeClient, err := testutil.NewFakeClientWithObjects(cm)
85+
Expect(err).NotTo(HaveOccurred())
86+
87+
store := NewConfigMapStore(fakeClient)
88+
completed, err := store.IsCompleted(context.Background(), "test-migration")
89+
Expect(err).NotTo(HaveOccurred())
90+
Expect(completed).To(BeFalse())
91+
})
92+
93+
It("should preserve existing migration records", func() {
94+
otherCompletedAt := "2026-04-29T10:25:06Z"
95+
cm := &corev1.ConfigMap{
96+
ObjectMeta: metav1.ObjectMeta{Name: ConfigMapName, Namespace: Namespace},
97+
Data: map[string]string{"other-migration": otherCompletedAt},
98+
}
99+
fakeClient, err := testutil.NewFakeClientWithObjects(cm)
100+
Expect(err).NotTo(HaveOccurred())
101+
102+
store := NewConfigMapStore(fakeClient)
103+
Expect(store.MarkCompleted(context.Background(), "test-migration")).To(Succeed())
104+
105+
updatedCM := &corev1.ConfigMap{}
106+
Expect(fakeClient.Get(context.Background(), types.NamespacedName{Name: ConfigMapName, Namespace: Namespace}, updatedCM)).To(Succeed())
107+
Expect(updatedCM.Data).To(HaveKeyWithValue("other-migration", otherCompletedAt))
108+
Expect(updatedCM.Data).To(HaveKey("test-migration"))
109+
})
110+
111+
It("should initialize empty data in existing ConfigMap", func() {
112+
cm := &corev1.ConfigMap{
113+
ObjectMeta: metav1.ObjectMeta{Name: ConfigMapName, Namespace: Namespace},
114+
}
115+
fakeClient, err := testutil.NewFakeClientWithObjects(cm)
116+
Expect(err).NotTo(HaveOccurred())
117+
118+
store := NewConfigMapStore(fakeClient)
119+
Expect(store.MarkCompleted(context.Background(), "test-migration")).To(Succeed())
120+
121+
updatedCM := &corev1.ConfigMap{}
122+
Expect(fakeClient.Get(context.Background(), types.NamespacedName{Name: ConfigMapName, Namespace: Namespace}, updatedCM)).To(Succeed())
123+
Expect(updatedCM.Data).To(HaveKey("test-migration"))
124+
})
78125
})

images/virtualization-artifact/pkg/migration/vm_running_transition_time_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,30 @@ var _ = Describe("Migration VM Running Transition Time", func() {
8585
Expect(cond).NotTo(BeNil())
8686
Expect(cond.LastTransitionTime.Equal(&wrongTime)).To(BeTrue())
8787
})
88+
89+
It("should preserve other migration records in shared ConfigMap", func() {
90+
creationTime := metav1.NewTime(time.Date(2026, 4, 29, 9, 0, 0, 0, time.UTC))
91+
wrongTime := metav1.NewTime(time.Date(2026, 4, 29, 10, 25, 6, 0, time.UTC))
92+
marker := &corev1.ConfigMap{
93+
ObjectMeta: metav1.ObjectMeta{Name: migrationstore.ConfigMapName, Namespace: migrationstore.Namespace},
94+
Data: map[string]string{"other-migration": "2026-04-29T10:30:00Z"},
95+
}
96+
97+
vm := newRunningVM(namespace, "vm", wrongTime)
98+
kvvmi := newKVVMI(namespace, "vm", creationTime)
99+
100+
fakeClient, err := testutil.NewFakeClientWithObjects(vm, kvvmi, marker)
101+
Expect(err).NotTo(HaveOccurred())
102+
103+
m, err := newVMRunningTransitionTime(fakeClient, testutil.NewNoOpLogger())
104+
Expect(err).NotTo(HaveOccurred())
105+
Expect(m.Migrate(context.Background())).To(Succeed())
106+
107+
updatedMarker := &corev1.ConfigMap{}
108+
Expect(fakeClient.Get(context.Background(), types.NamespacedName{Name: migrationstore.ConfigMapName, Namespace: migrationstore.Namespace}, updatedMarker)).To(Succeed())
109+
Expect(updatedMarker.Data).To(HaveKeyWithValue("other-migration", "2026-04-29T10:30:00Z"))
110+
Expect(updatedMarker.Data).To(HaveKey(vmRunningTransitionTimeMigrationName))
111+
})
88112
})
89113

90114
func newRunningVM(namespace, name string, transitionTime metav1.Time) *v1alpha2.VirtualMachine {

0 commit comments

Comments
 (0)