Skip to content

Commit 2e32a5e

Browse files
authored
test(jindocache): migrate status_test.go to Ginkgo/Gomega (#5623)
Signed-off-by: Harsh <harshmastic@gmail.com>
1 parent 44aec05 commit 2e32a5e

1 file changed

Lines changed: 72 additions & 81 deletions

File tree

pkg/ddc/jindocache/status_test.go

Lines changed: 72 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -17,110 +17,101 @@ limitations under the License.
1717
package jindocache
1818

1919
import (
20-
"testing"
21-
2220
"github.com/agiledragon/gomonkey/v2"
2321
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
2422
"github.com/fluid-cloudnative/fluid/pkg/utils"
2523
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
24+
. "github.com/onsi/ginkgo/v2"
25+
. "github.com/onsi/gomega"
2626
appsv1 "k8s.io/api/apps/v1"
2727
v1 "k8s.io/api/core/v1"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
"k8s.io/apimachinery/pkg/runtime"
3030
)
3131

32-
func TestCheckAndUpdateRuntimeStatus(t *testing.T) {
33-
34-
masterInputs := []*appsv1.StatefulSet{
35-
{
36-
ObjectMeta: metav1.ObjectMeta{
37-
Name: "hbase-jindofs-master",
38-
Namespace: "fluid",
39-
},
40-
Status: appsv1.StatefulSetStatus{
41-
ReadyReplicas: 1,
32+
var _ = Describe("CheckAndUpdateRuntimeStatus", func() {
33+
var (
34+
masterInputs []*appsv1.StatefulSet
35+
workerInputs []appsv1.StatefulSet
36+
runtimeInputs []*datav1alpha1.JindoRuntime
37+
)
38+
39+
BeforeEach(func() {
40+
masterInputs = []*appsv1.StatefulSet{
41+
{
42+
ObjectMeta: metav1.ObjectMeta{
43+
Name: "hbase-jindofs-master",
44+
Namespace: "fluid",
45+
},
46+
Status: appsv1.StatefulSetStatus{
47+
ReadyReplicas: 1,
48+
},
4249
},
43-
},
44-
}
50+
}
4551

46-
var workerInputs = []appsv1.StatefulSet{
47-
{
48-
ObjectMeta: metav1.ObjectMeta{
49-
Name: "hbase-jindofs-worker",
50-
Namespace: "fluid",
51-
},
52-
Status: appsv1.StatefulSetStatus{
53-
Replicas: 3,
54-
ReadyReplicas: 3,
52+
workerInputs = []appsv1.StatefulSet{
53+
{
54+
ObjectMeta: metav1.ObjectMeta{
55+
Name: "hbase-jindofs-worker",
56+
Namespace: "fluid",
57+
},
58+
Status: appsv1.StatefulSetStatus{
59+
Replicas: 3,
60+
ReadyReplicas: 3,
61+
},
5562
},
56-
},
57-
}
63+
}
5864

59-
runtimeInputs := []*datav1alpha1.JindoRuntime{
60-
{
61-
ObjectMeta: metav1.ObjectMeta{
62-
Name: "hbase",
63-
Namespace: "fluid",
64-
},
65-
Spec: datav1alpha1.JindoRuntimeSpec{
66-
Replicas: 3, // 2
67-
},
68-
Status: datav1alpha1.RuntimeStatus{
69-
CurrentWorkerNumberScheduled: 2,
70-
CurrentMasterNumberScheduled: 2, // 0
71-
CurrentFuseNumberScheduled: 2,
72-
DesiredMasterNumberScheduled: 3,
73-
DesiredWorkerNumberScheduled: 2,
74-
DesiredFuseNumberScheduled: 3,
75-
Conditions: []datav1alpha1.RuntimeCondition{
76-
utils.NewRuntimeCondition(datav1alpha1.RuntimeWorkersInitialized, datav1alpha1.RuntimeWorkersInitializedReason, "The workers are initialized.", v1.ConditionTrue),
77-
utils.NewRuntimeCondition(datav1alpha1.RuntimeFusesInitialized, datav1alpha1.RuntimeFusesInitializedReason, "The fuses are initialized.", v1.ConditionTrue),
65+
runtimeInputs = []*datav1alpha1.JindoRuntime{
66+
{
67+
ObjectMeta: metav1.ObjectMeta{
68+
Name: "hbase",
69+
Namespace: "fluid",
70+
},
71+
Spec: datav1alpha1.JindoRuntimeSpec{
72+
Replicas: 3, // 2
73+
},
74+
Status: datav1alpha1.RuntimeStatus{
75+
CurrentWorkerNumberScheduled: 2,
76+
CurrentMasterNumberScheduled: 2, // 0
77+
CurrentFuseNumberScheduled: 2,
78+
DesiredMasterNumberScheduled: 3,
79+
DesiredWorkerNumberScheduled: 2,
80+
DesiredFuseNumberScheduled: 3,
81+
Conditions: []datav1alpha1.RuntimeCondition{
82+
utils.NewRuntimeCondition(datav1alpha1.RuntimeWorkersInitialized, datav1alpha1.RuntimeWorkersInitializedReason, "The workers are initialized.", v1.ConditionTrue),
83+
utils.NewRuntimeCondition(datav1alpha1.RuntimeFusesInitialized, datav1alpha1.RuntimeFusesInitializedReason, "The fuses are initialized.", v1.ConditionTrue),
84+
},
85+
WorkerPhase: "NotReady",
86+
FusePhase: "NotReady",
7887
},
79-
WorkerPhase: "NotReady",
80-
FusePhase: "NotReady",
8188
},
82-
},
83-
}
84-
85-
objs := []runtime.Object{}
86-
for _, masterInput := range masterInputs {
87-
objs = append(objs, masterInput.DeepCopy())
88-
}
89+
}
90+
})
8991

90-
for _, workerInput := range workerInputs {
91-
objs = append(objs, workerInput.DeepCopy())
92-
}
92+
It("should check and update runtime status for hbase", func() {
93+
objs := []runtime.Object{}
94+
for _, masterInput := range masterInputs {
95+
objs = append(objs, masterInput.DeepCopy())
96+
}
9397

94-
for _, runtimeInput := range runtimeInputs {
95-
objs = append(objs, runtimeInput.DeepCopy())
96-
}
97-
fakeClient := fake.NewFakeClientWithScheme(testScheme, objs...)
98-
// engine := newJindoCacheEngineREP(fakeClient, testCase.name, testCase.namespace)
98+
for _, workerInput := range workerInputs {
99+
objs = append(objs, workerInput.DeepCopy())
100+
}
99101

100-
testCases := []struct {
101-
testName string
102-
name string
103-
namespace string
104-
isErr bool
105-
}{
106-
// TODO: add more unit tests
107-
{testName: "hbase",
108-
name: "hbase",
109-
namespace: "fluid"},
110-
}
102+
for _, runtimeInput := range runtimeInputs {
103+
objs = append(objs, runtimeInput.DeepCopy())
104+
}
105+
fakeClient := fake.NewFakeClientWithScheme(testScheme, objs...)
111106

112-
for _, testCase := range testCases {
113-
engine := newJindoCacheEngineREP(fakeClient, testCase.name, testCase.namespace)
107+
engine := newJindoCacheEngineREP(fakeClient, "hbase", "fluid")
114108

115109
patches := gomonkey.ApplyPrivateMethod(engine, "syncCacheModeRuntimeStatus", func() (ready bool, err error) {
116110
return true, nil
117111
})
112+
defer patches.Reset()
118113

119114
_, err := engine.CheckAndUpdateRuntimeStatus()
120-
if err != nil {
121-
t.Errorf("testcase %s Failed due to %v", testCase.testName, err)
122-
}
123-
124-
patches.Reset()
125-
}
126-
}
115+
Expect(err).NotTo(HaveOccurred())
116+
})
117+
})

0 commit comments

Comments
 (0)