Skip to content

Commit 56549d5

Browse files
authored
test(ddc/goosefs): migrate api_gateway tests to ginkgo (#5562)
* test(ddc/goosefs): migrate api_gateway tests to ginkgo Signed-off-by: Harsh <harshmastic@gmail.com> * refactor: remove unused name field from testCase Signed-off-by: Harsh <harshmastic@gmail.com> --------- Signed-off-by: Harsh <harshmastic@gmail.com>
1 parent 83d85cb commit 56549d5

1 file changed

Lines changed: 65 additions & 65 deletions

File tree

pkg/ddc/goosefs/api_gateway_test.go

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ package goosefs
1818

1919
import (
2020
"fmt"
21-
"reflect"
22-
"testing"
21+
22+
. "github.com/onsi/ginkgo/v2"
23+
. "github.com/onsi/gomega"
2324

2425
datav1alpha1 "github.com/fluid-cloudnative/fluid/api/v1alpha1"
2526
"github.com/fluid-cloudnative/fluid/pkg/common"
@@ -29,45 +30,7 @@ import (
2930
"sigs.k8s.io/controller-runtime/pkg/client"
3031
)
3132

32-
func TestGetAPIGatewayStatus(t *testing.T) {
33-
endpointFormat := "%s-master-0.%s:%d"
34-
testCases := map[string]struct {
35-
engineName string
36-
engineNamespace string
37-
port int32
38-
wantStatus *datav1alpha1.APIGatewayStatus
39-
}{
40-
"test GetAPIGatewayStatus case 1": {
41-
engineName: "fluid",
42-
engineNamespace: "default",
43-
port: 8080,
44-
wantStatus: &datav1alpha1.APIGatewayStatus{
45-
Endpoint: fmt.Sprintf(endpointFormat, "fluid", "default", 8080),
46-
},
47-
},
48-
"test GetAPIGatewayStatus case 2": {
49-
engineName: "demo",
50-
engineNamespace: common.NamespaceFluidSystem,
51-
port: 80,
52-
wantStatus: &datav1alpha1.APIGatewayStatus{
53-
Endpoint: fmt.Sprintf(endpointFormat, "demo", common.NamespaceFluidSystem, 80),
54-
},
55-
},
56-
}
57-
58-
for k, item := range testCases {
59-
e := mockGooseFSEngineWithClient(item.engineName, item.engineNamespace, item.port)
60-
got, _ := e.GetAPIGatewayStatus()
61-
62-
if !reflect.DeepEqual(got, item.wantStatus) {
63-
t.Errorf("%s check failure,want:%v,got:%v", k, item.wantStatus, got)
64-
}
65-
66-
}
67-
}
68-
6933
func mockGooseFSEngineWithClient(name, ns string, port int32) *GooseFSEngine {
70-
7134
var mockClient client.Client
7235

7336
mockSvc := &corev1.Service{
@@ -95,35 +58,72 @@ func mockGooseFSEngineWithClient(name, ns string, port int32) *GooseFSEngine {
9558
return e
9659
}
9760

98-
func TestQueryAPIGatewayEndpoint(t *testing.T) {
61+
var _ = Describe("APIGateway", func() {
9962
endpointFormat := "%s-master-0.%s:%d"
100-
testCases := map[string]struct {
63+
64+
type testCase struct {
10165
engineName string
10266
engineNamespace string
10367
port int32
10468
wantEndpoint string
105-
}{
106-
"test GetAPIGatewayStatus case 1": {
107-
engineName: "fluid",
108-
engineNamespace: "default",
109-
port: 8080,
110-
wantEndpoint: fmt.Sprintf(endpointFormat, "fluid", "default", 8080),
111-
},
112-
"test GetAPIGatewayStatus case 2": {
113-
engineName: "demo",
114-
engineNamespace: common.NamespaceFluidSystem,
115-
port: 80,
116-
wantEndpoint: fmt.Sprintf(endpointFormat, "demo", common.NamespaceFluidSystem, 80),
117-
},
11869
}
11970

120-
for k, item := range testCases {
121-
e := mockGooseFSEngineWithClient(item.engineName, item.engineNamespace, item.port)
122-
got, _ := e.queryAPIGatewayEndpoint()
123-
124-
if !reflect.DeepEqual(got, item.wantEndpoint) {
125-
t.Errorf("%s check failure,want:%v,got:%v", k, item.wantEndpoint, got)
126-
}
127-
128-
}
129-
}
71+
Describe("GetAPIGatewayStatus", func() {
72+
DescribeTable("should return correct API gateway status",
73+
func(tc testCase) {
74+
e := mockGooseFSEngineWithClient(tc.engineName, tc.engineNamespace, tc.port)
75+
got, err := e.GetAPIGatewayStatus()
76+
77+
Expect(err).NotTo(HaveOccurred())
78+
expectedStatus := &datav1alpha1.APIGatewayStatus{
79+
Endpoint: fmt.Sprintf(endpointFormat, tc.engineName, tc.engineNamespace, tc.port),
80+
}
81+
Expect(got).To(Equal(expectedStatus))
82+
},
83+
Entry("fluid engine in default namespace",
84+
testCase{
85+
engineName: "fluid",
86+
engineNamespace: "default",
87+
port: 8080,
88+
wantEndpoint: fmt.Sprintf(endpointFormat, "fluid", "default", 8080),
89+
},
90+
),
91+
Entry("demo engine in fluid-system namespace",
92+
testCase{
93+
engineName: "demo",
94+
engineNamespace: common.NamespaceFluidSystem,
95+
port: 80,
96+
wantEndpoint: fmt.Sprintf(endpointFormat, "demo", common.NamespaceFluidSystem, 80),
97+
},
98+
),
99+
)
100+
})
101+
102+
Describe("queryAPIGatewayEndpoint", func() {
103+
DescribeTable("should return correct endpoint",
104+
func(tc testCase) {
105+
e := mockGooseFSEngineWithClient(tc.engineName, tc.engineNamespace, tc.port)
106+
got, err := e.queryAPIGatewayEndpoint()
107+
108+
Expect(err).NotTo(HaveOccurred())
109+
Expect(got).To(Equal(tc.wantEndpoint))
110+
},
111+
Entry("fluid engine in default namespace",
112+
testCase{
113+
engineName: "fluid",
114+
engineNamespace: "default",
115+
port: 8080,
116+
wantEndpoint: fmt.Sprintf(endpointFormat, "fluid", "default", 8080),
117+
},
118+
),
119+
Entry("demo engine in fluid-system namespace",
120+
testCase{
121+
engineName: "demo",
122+
engineNamespace: common.NamespaceFluidSystem,
123+
port: 80,
124+
wantEndpoint: fmt.Sprintf(endpointFormat, "demo", common.NamespaceFluidSystem, 80),
125+
},
126+
),
127+
)
128+
})
129+
})

0 commit comments

Comments
 (0)