Skip to content

Commit 855964f

Browse files
authored
test(utils): migrate tests to ginkgo of pkg/utils/kubeclient/service_test.go (#5580)
Signed-off-by: adity1raut <araut7798@gmail.com>
1 parent 4d0b783 commit 855964f

1 file changed

Lines changed: 40 additions & 46 deletions

File tree

pkg/utils/kubeclient/service_test.go

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,58 @@ limitations under the License.
1616
package kubeclient
1717

1818
import (
19-
"testing"
20-
2119
"github.com/fluid-cloudnative/fluid/pkg/common"
2220
"github.com/fluid-cloudnative/fluid/pkg/utils/fake"
21+
. "github.com/onsi/ginkgo/v2"
22+
. "github.com/onsi/gomega"
2323
v1 "k8s.io/api/core/v1"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/apimachinery/pkg/runtime"
26+
"sigs.k8s.io/controller-runtime/pkg/client"
2627
)
2728

2829
// Use fake client because of it will be maintained in the long term
2930
// due to https://github.com/kubernetes-sigs/controller-runtime/pull/1101
30-
func TestGetServiceByName(t *testing.T) {
31-
namespace := "default"
32-
testServiceInputs := []*v1.Service{{
33-
ObjectMeta: metav1.ObjectMeta{Name: "svc1"},
34-
Spec: v1.ServiceSpec{},
35-
}, {
36-
ObjectMeta: metav1.ObjectMeta{Name: "svc2", Annotations: common.GetExpectedFluidAnnotations()},
37-
Spec: v1.ServiceSpec{},
38-
}}
31+
var _ = Describe("GetServiceByName", func() {
32+
var (
33+
namespace string
34+
testServiceInputs []*v1.Service
35+
testServices []runtime.Object
36+
mockClient client.Client
37+
)
3938

40-
testServices := []runtime.Object{}
39+
BeforeEach(func() {
40+
namespace = "default"
41+
testServiceInputs = []*v1.Service{
42+
{
43+
ObjectMeta: metav1.ObjectMeta{Name: "svc1"},
44+
Spec: v1.ServiceSpec{},
45+
},
46+
{
47+
ObjectMeta: metav1.ObjectMeta{Name: "svc2", Annotations: common.GetExpectedFluidAnnotations()},
48+
Spec: v1.ServiceSpec{},
49+
},
50+
}
4151

42-
for _, pv := range testServiceInputs {
43-
testServices = append(testServices, pv.DeepCopy())
44-
}
52+
testServices = []runtime.Object{}
53+
for _, pv := range testServiceInputs {
54+
testServices = append(testServices, pv.DeepCopy())
55+
}
4556

46-
client := fake.NewFakeClientWithScheme(testScheme, testServices...)
57+
mockClient = fake.NewFakeClientWithScheme(testScheme, testServices...)
58+
})
4759

48-
type args struct {
49-
name string
50-
namespace string
51-
}
52-
tests := []struct {
53-
name string
54-
args args
55-
}{
56-
{
57-
name: "service doesn't exist",
58-
args: args{
59-
name: "notExist",
60-
namespace: namespace,
61-
},
62-
},
63-
{
64-
name: "service is not created by fluid",
65-
args: args{
66-
name: "svc1",
67-
namespace: namespace,
68-
},
69-
},
70-
}
71-
for _, tt := range tests {
72-
t.Run(tt.name, func(t *testing.T) {
73-
if _, err := GetServiceByName(client, tt.args.name, tt.args.namespace); err != nil {
74-
t.Errorf("testcase %v GetServiceByName() got error %v", tt.name, err)
75-
}
60+
Context("when service doesn't exist", func() {
61+
It("should not return an error", func() {
62+
_, err := GetServiceByName(mockClient, "notExist", namespace)
63+
Expect(err).NotTo(HaveOccurred())
7664
})
77-
}
65+
})
7866

79-
}
67+
Context("when service is not created by fluid", func() {
68+
It("should not return an error", func() {
69+
_, err := GetServiceByName(mockClient, "svc1", namespace)
70+
Expect(err).NotTo(HaveOccurred())
71+
})
72+
})
73+
})

0 commit comments

Comments
 (0)