Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions pkg/utils/kubeclient/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ var _ = Describe("GetServiceByName", func() {
namespace = "default"
testServiceInputs = []*v1.Service{
{
ObjectMeta: metav1.ObjectMeta{Name: "svc1"},
ObjectMeta: metav1.ObjectMeta{Name: "svc1", Namespace: namespace},
Spec: v1.ServiceSpec{},
},
{
ObjectMeta: metav1.ObjectMeta{Name: "svc2", Annotations: common.GetExpectedFluidAnnotations()},
ObjectMeta: metav1.ObjectMeta{Name: "svc2", Namespace: namespace, Annotations: common.GetExpectedFluidAnnotations()},
Spec: v1.ServiceSpec{},
},
}
Expand All @@ -58,16 +58,37 @@ var _ = Describe("GetServiceByName", func() {
})

Context("when service doesn't exist", func() {
It("should not return an error", func() {
_, err := GetServiceByName(mockClient, "notExist", namespace)
It("should return nil service and no error", func() {
svc, err := GetServiceByName(mockClient, "notExist", namespace)
Expect(err).NotTo(HaveOccurred())
Expect(svc).To(BeNil())
})
})

Context("when service is not created by fluid", func() {
It("should not return an error", func() {
_, err := GetServiceByName(mockClient, "svc1", namespace)
It("should return the existing service", func() {
svc, err := GetServiceByName(mockClient, "svc1", namespace)
Expect(err).NotTo(HaveOccurred())
Expect(svc).NotTo(BeNil())
Expect(svc.Name).To(Equal("svc1"))
})
})

Context("when service is created by fluid", func() {
It("should return the existing service", func() {
svc, err := GetServiceByName(mockClient, "svc2", namespace)
Expect(err).NotTo(HaveOccurred())
Expect(svc).NotTo(BeNil())
Expect(svc.Name).To(Equal("svc2"))
Expect(svc.Annotations).To(Equal(common.GetExpectedFluidAnnotations()))
})
})

Context("when namespace doesn't match", func() {
It("should return nil service and no error", func() {
svc, err := GetServiceByName(mockClient, "svc1", "another-namespace")
Expect(err).NotTo(HaveOccurred())
Expect(svc).To(BeNil())
})
})
})
Loading