Skip to content

Commit

Permalink
Add tests for WatcherAPI service addition
Browse files Browse the repository at this point in the history
  • Loading branch information
cescgina committed Jan 14, 2025
1 parent 90a38d5 commit bcade20
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/functional/watcher_test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type WatcherTestData struct {
RoleBindingName types.NamespacedName
WatcherDBSync types.NamespacedName
WatcherAPIDeployment types.NamespacedName
WatcherPublicServiceName types.NamespacedName
WatcherInternalServiceName types.NamespacedName
}

// GetWatcherTestData is a function that initialize the WatcherTestData
Expand Down Expand Up @@ -115,5 +117,13 @@ func GetWatcherTestData(watcherName types.NamespacedName) WatcherTestData {
Namespace: watcherName.Namespace,
Name: "watcher-api-api",
},
WatcherPublicServiceName: types.NamespacedName{
Namespace: watcherName.Namespace,
Name: "watcher-public",
},
WatcherInternalServiceName: types.NamespacedName{
Namespace: watcherName.Namespace,
Name: "watcher-internal",
},
}
}
13 changes: 13 additions & 0 deletions tests/functional/watcherapi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ var _ = Describe("WatcherAPI controller", func() {
Expect(container.LivenessProbe.HTTPGet.Port.IntVal).To(Equal(int32(9322)))
Expect(container.ReadinessProbe.HTTPGet.Port.IntVal).To(Equal(int32(9322)))
})
It("creates the public and internal services for the watcher-api service", func() {
th.ExpectCondition(
watcherTest.WatcherAPI,
ConditionGetterFunc(WatcherAPIConditionGetter),
condition.CreateServiceReadyCondition,
corev1.ConditionTrue,
)
public := th.GetService(watcherTest.WatcherPublicServiceName)
Expect(public.Labels["service"]).To(Equal("watcher-api"))
internal := th.GetService(watcherTest.WatcherInternalServiceName)
Expect(internal.Labels["service"]).To(Equal("watcher-api"))

})
})
When("the secret is created but missing fields", func() {
BeforeEach(func() {
Expand Down
38 changes: 38 additions & 0 deletions tests/kuttl/test-suites/default/watcher-api/03-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ status:
reason: Ready
status: "True"
type: Ready
- message: Create service completed
reason: Ready
status: "True"
type: CreateServiceReady
- message: Deployment completed
reason: Ready
status: "True"
Expand Down Expand Up @@ -65,3 +69,37 @@ spec:
- name: watcher-api
status:
phase: Running
---
apiVersion: v1
kind: Service
metadata:
labels:
endpoint: internal
service: watcher-api
name: watcher-internal
spec:
ports:
- name: watcher-internal
port: 9322
protocol: TCP
targetPort: 9322
selector:
service: watcher-api
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
labels:
endpoint: public
service: watcher-api
name: watcher-public
spec:
ports:
- name: watcher-public
port: 9322
protocol: TCP
targetPort: 9322
selector:
service: watcher-api
type: ClusterIP
16 changes: 16 additions & 0 deletions tests/kuttl/test-suites/default/watcher-api/05-errors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,19 @@ kind: Pod
metadata:
labels:
service: watcher-api
---
apiVersion: v1
kind: Service
metadata:
labels:
endpoint: internal
service: watcher-api
name: watcher-internal
---
apiVersion: v1
kind: Service
metadata:
labels:
endpoint: public
service: watcher-api
name: watcher-public

0 comments on commit bcade20

Please sign in to comment.