Skip to content

Commit 997e8fd

Browse files
authored
test(ddc/goosefs): migrate transform_api_gateway tests to ginkgo (#5554)
* test(ddc/goosefs): migrate transform_api_gateway tests to ginkgo Signed-off-by: Harsh <harshmastic@gmail.com> * fix: set shouldMatch=true for success cases Signed-off-by: Harsh <harshmastic@gmail.com> --------- Signed-off-by: Harsh <harshmastic@gmail.com>
1 parent e4a83fb commit 997e8fd

1 file changed

Lines changed: 43 additions & 38 deletions

File tree

pkg/ddc/goosefs/transform_api_gateway_test.go

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,75 +17,80 @@ limitations under the License.
1717
package goosefs
1818

1919
import (
20-
"testing"
20+
. "github.com/onsi/ginkgo/v2"
21+
. "github.com/onsi/gomega"
2122

2223
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
2324
)
2425

25-
func TestTransformAPIGateway(t *testing.T) {
26-
var engine = &GooseFSEngine{}
27-
var tests = []struct {
28-
runtime *datav1alpha1.GooseFSRuntime
29-
value *GooseFS
30-
}{
31-
{
32-
runtime: &datav1alpha1.GooseFSRuntime{
26+
var _ = Describe("GooseFS", func() {
27+
DescribeTable("transformAPIGateway",
28+
func(runtime *datav1alpha1.GooseFSRuntime, value *GooseFS, expectError bool, shouldMatch bool) {
29+
engine := &GooseFSEngine{}
30+
err := engine.transformAPIGateway(runtime, value)
31+
32+
if expectError {
33+
Expect(err).To(HaveOccurred())
34+
} else {
35+
Expect(err).NotTo(HaveOccurred())
36+
if shouldMatch {
37+
Expect(runtime.Spec.APIGateway.Enabled).To(Equal(value.APIGateway.Enabled))
38+
}
39+
}
40+
},
41+
Entry("should sync when runtime enabled and value disabled",
42+
&datav1alpha1.GooseFSRuntime{
3343
Spec: datav1alpha1.GooseFSRuntimeSpec{
3444
APIGateway: datav1alpha1.GooseFSCompTemplateSpec{
3545
Enabled: true,
3646
},
3747
},
3848
},
39-
value: &GooseFS{
49+
&GooseFS{
4050
APIGateway: APIGateway{
4151
Enabled: false,
4252
},
4353
},
44-
},
45-
{
46-
runtime: &datav1alpha1.GooseFSRuntime{
54+
false,
55+
true,
56+
),
57+
Entry("should sync when runtime disabled and value enabled",
58+
&datav1alpha1.GooseFSRuntime{
4759
Spec: datav1alpha1.GooseFSRuntimeSpec{
4860
APIGateway: datav1alpha1.GooseFSCompTemplateSpec{
4961
Enabled: false,
5062
},
5163
},
5264
},
53-
value: &GooseFS{
65+
&GooseFS{
5466
APIGateway: APIGateway{
5567
Enabled: true,
5668
},
5769
},
58-
},
59-
{
60-
runtime: nil,
61-
value: &GooseFS{
70+
false,
71+
true,
72+
),
73+
Entry("should return error when runtime is nil",
74+
nil,
75+
&GooseFS{
6276
APIGateway: APIGateway{
6377
Enabled: false,
6478
},
6579
},
66-
},
67-
{
68-
runtime: &datav1alpha1.GooseFSRuntime{
80+
true,
81+
false,
82+
),
83+
Entry("should return error when value is nil",
84+
&datav1alpha1.GooseFSRuntime{
6985
Spec: datav1alpha1.GooseFSRuntimeSpec{
7086
APIGateway: datav1alpha1.GooseFSCompTemplateSpec{
7187
Enabled: true,
7288
},
7389
},
7490
},
75-
value: nil,
76-
},
77-
}
78-
for _, test := range tests {
79-
err := engine.transformAPIGateway(test.runtime, test.value)
80-
if test.runtime == nil || test.value == nil {
81-
if err == nil {
82-
t.Errorf("should return err if it's possible to lead to nil pointer")
83-
}
84-
} else if test.runtime.Spec.APIGateway.Enabled != test.value.APIGateway.Enabled {
85-
t.Errorf("testcase cannot paas because of wrong result,%t != %t",
86-
test.runtime.Spec.APIGateway.Enabled,
87-
test.value.APIGateway.Enabled)
88-
}
89-
}
90-
91-
}
91+
nil,
92+
true,
93+
false,
94+
),
95+
)
96+
})

0 commit comments

Comments
 (0)