Skip to content

Commit 5a2f6e1

Browse files
committed
test(dataprocess): migrate package tests to ginkgo v2
Signed-off-by: Harsh <harshmastic@gmail.com>
1 parent 7e7aeb0 commit 5a2f6e1

4 files changed

Lines changed: 727 additions & 246 deletions

File tree

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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 dataprocess
18+
19+
import (
20+
"context"
21+
"time"
22+
23+
. "github.com/onsi/ginkgo/v2"
24+
. "github.com/onsi/gomega"
25+
26+
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
27+
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
28+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/apimachinery/pkg/runtime"
30+
"k8s.io/apimachinery/pkg/types"
31+
"k8s.io/client-go/tools/record"
32+
ctrl "sigs.k8s.io/controller-runtime"
33+
logf "sigs.k8s.io/controller-runtime/pkg/log"
34+
)
35+
36+
// newTestDataProcessReconciler builds a DataProcessReconciler for unit tests.
37+
func newTestDataProcessReconciler(s *runtime.Scheme, objs ...runtime.Object) *DataProcessReconciler {
38+
if s == nil {
39+
s = runtime.NewScheme()
40+
_ = datav1alpha1.AddToScheme(s)
41+
}
42+
fakeClient := fake.NewFakeClientWithScheme(s, objs...)
43+
log := logf.Log.WithName("dataprocess-test")
44+
recorder := record.NewFakeRecorder(32)
45+
return NewDataProcessReconciler(fakeClient, log, s, recorder)
46+
}
47+
48+
var _ = Describe("DataProcessReconciler", func() {
49+
50+
Describe("ControllerName", func() {
51+
It("should return the expected controller name", func() {
52+
r := newTestDataProcessReconciler(nil)
53+
Expect(r.ControllerName()).To(Equal("DataProcessReconciler"))
54+
})
55+
})
56+
57+
Describe("NewDataProcessReconciler", func() {
58+
It("should create a non-nil reconciler with a Scheme", func() {
59+
s := runtime.NewScheme()
60+
_ = datav1alpha1.AddToScheme(s)
61+
r := newTestDataProcessReconciler(s)
62+
Expect(r).NotTo(BeNil())
63+
Expect(r.Scheme).NotTo(BeNil())
64+
})
65+
})
66+
67+
Describe("Build", func() {
68+
It("should return a dataProcessOperation for a valid DataProcess object", func() {
69+
r := newTestDataProcessReconciler(nil)
70+
dp := &datav1alpha1.DataProcess{
71+
ObjectMeta: v1.ObjectMeta{Name: "test", Namespace: "default"},
72+
}
73+
op, err := r.Build(dp)
74+
Expect(err).NotTo(HaveOccurred())
75+
Expect(op).NotTo(BeNil())
76+
})
77+
78+
It("should return an error when given a non-DataProcess object", func() {
79+
r := newTestDataProcessReconciler(nil)
80+
ds := &datav1alpha1.Dataset{
81+
ObjectMeta: v1.ObjectMeta{Name: "ds", Namespace: "default"},
82+
}
83+
op, err := r.Build(ds)
84+
Expect(err).To(HaveOccurred())
85+
Expect(op).To(BeNil())
86+
})
87+
})
88+
89+
Describe("Reconcile", func() {
90+
It("should return no error when the DataProcess is not found", func() {
91+
s := runtime.NewScheme()
92+
_ = datav1alpha1.AddToScheme(s)
93+
r := newTestDataProcessReconciler(s)
94+
// No DataProcess objects registered — should get NotFound and return cleanly.
95+
req := ctrl.Request{
96+
NamespacedName: types.NamespacedName{Name: "missing", Namespace: "default"},
97+
}
98+
result, err := r.Reconcile(context.TODO(), req)
99+
Expect(err).NotTo(HaveOccurred())
100+
Expect(result).To(Equal(ctrl.Result{}))
101+
})
102+
103+
It("should reconcile successfully when DataProcess exists", func() {
104+
s := runtime.NewScheme()
105+
_ = datav1alpha1.AddToScheme(s)
106+
dp := &datav1alpha1.DataProcess{
107+
ObjectMeta: v1.ObjectMeta{Name: "test", Namespace: "default"},
108+
Spec: datav1alpha1.DataProcessSpec{
109+
Dataset: datav1alpha1.TargetDatasetWithMountPath{
110+
TargetDataset: datav1alpha1.TargetDataset{
111+
Name: "ds",
112+
Namespace: "default",
113+
},
114+
MountPath: "/data",
115+
},
116+
Processor: datav1alpha1.Processor{
117+
Script: &datav1alpha1.ScriptProcessor{
118+
Source: "echo hello",
119+
},
120+
},
121+
},
122+
}
123+
r := newTestDataProcessReconciler(s, dp)
124+
req := ctrl.Request{
125+
NamespacedName: types.NamespacedName{Name: "test", Namespace: "default"},
126+
}
127+
result, err := r.Reconcile(context.TODO(), req)
128+
Expect(err).NotTo(HaveOccurred())
129+
Expect(result).To(Equal(ctrl.Result{RequeueAfter: 20 * time.Second}))
130+
})
131+
})
132+
})

0 commit comments

Comments
 (0)