Skip to content

Commit 14d0ee1

Browse files
authored
test(datamigrate): migrate controller tests to Ginkgo v2 (#5710)
* test(datamigrate): migrate controller tests to Ginkgo v2 Signed-off-by: Harsh <harshmastic@gmail.com> * test(datamigrate): address Copilot review findings - Fix misleading comment on running-job test (returns DeepCopy, not nil) - Rename NodeAffinity test to reflect actual assertion scope - Improve suspend test: start STS at 0 replicas for observable scaling, assert job.Spec.Suspend is flipped to false Signed-off-by: Harsh <harshmastic@gmail.com> * test(datamigrate): deduplicate repeated test literals Signed-off-by: Harsh <harshmastic@gmail.com> --------- Signed-off-by: Harsh <harshmastic@gmail.com>
1 parent 58feb82 commit 14d0ee1

4 files changed

Lines changed: 1019 additions & 347 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Copyright 2026 The Fluid Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package datamigrate
18+
19+
import (
20+
. "github.com/onsi/ginkgo/v2"
21+
. "github.com/onsi/gomega"
22+
23+
"k8s.io/apimachinery/pkg/runtime"
24+
"k8s.io/client-go/tools/record"
25+
26+
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
27+
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
28+
)
29+
30+
var _ = Describe("DataMigrateReconciler", func() {
31+
Describe("NewDataMigrateReconciler", func() {
32+
It("should create a reconciler with the provided fields", func() {
33+
scheme := runtime.NewScheme()
34+
fakeClient := fake.NewFakeClientWithScheme(scheme)
35+
log := fake.NullLogger()
36+
recorder := record.NewFakeRecorder(10)
37+
38+
r := NewDataMigrateReconciler(fakeClient, log, scheme, recorder)
39+
40+
Expect(r).NotTo(BeNil())
41+
Expect(r.Scheme).To(Equal(scheme))
42+
Expect(r.OperationReconciler).NotTo(BeNil())
43+
})
44+
})
45+
46+
Describe("ControllerName", func() {
47+
It("should return DataMigrateReconciler", func() {
48+
scheme := runtime.NewScheme()
49+
fakeClient := fake.NewFakeClientWithScheme(scheme)
50+
log := fake.NullLogger()
51+
recorder := record.NewFakeRecorder(10)
52+
53+
r := NewDataMigrateReconciler(fakeClient, log, scheme, recorder)
54+
55+
Expect(r.ControllerName()).To(Equal("DataMigrateReconciler"))
56+
})
57+
})
58+
59+
Describe("Build", func() {
60+
It("should return a dataMigrateOperation when given a DataMigrate object", func() {
61+
scheme := runtime.NewScheme()
62+
fakeClient := fake.NewFakeClientWithScheme(scheme)
63+
log := fake.NullLogger()
64+
recorder := record.NewFakeRecorder(10)
65+
66+
r := NewDataMigrateReconciler(fakeClient, log, scheme, recorder)
67+
68+
dm := &datav1alpha1.DataMigrate{}
69+
dm.Name = "test-migrate"
70+
dm.Namespace = "default"
71+
72+
op, err := r.Build(dm)
73+
74+
Expect(err).NotTo(HaveOccurred())
75+
Expect(op).NotTo(BeNil())
76+
})
77+
78+
It("should return an error when given a non-DataMigrate object", func() {
79+
scheme := runtime.NewScheme()
80+
fakeClient := fake.NewFakeClientWithScheme(scheme)
81+
log := fake.NullLogger()
82+
recorder := record.NewFakeRecorder(10)
83+
84+
r := NewDataMigrateReconciler(fakeClient, log, scheme, recorder)
85+
86+
notDM := &datav1alpha1.DataLoad{}
87+
88+
op, err := r.Build(notDM)
89+
90+
Expect(err).To(HaveOccurred())
91+
Expect(op).To(BeNil())
92+
})
93+
})
94+
})

0 commit comments

Comments
 (0)