Skip to content

Commit

Permalink
Add tests for Watcher API deployment addition
Browse files Browse the repository at this point in the history
Add kuttl and funtional tests for the code responsible for creating the
Watcher API deployment.
  • Loading branch information
cescgina committed Jan 7, 2025
1 parent ccbb45c commit 1d7124b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func GetDefaultWatcherAPISpec() map[string]interface{} {
"databaseInstance": "openstack",
"secret": SecretName,
"memcachedInstance": "memcached",
"serviceAccount": "watcher-sa",
"containerImage": "test://watcher",
}
}

Expand Down
5 changes: 5 additions & 0 deletions tests/functional/watcher_test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type WatcherTestData struct {
RoleName types.NamespacedName
RoleBindingName types.NamespacedName
WatcherDBSync types.NamespacedName
WatcherAPIDeployment types.NamespacedName
}

// GetWatcherTestData is a function that initialize the WatcherTestData
Expand Down Expand Up @@ -110,5 +111,9 @@ func GetWatcherTestData(watcherName types.NamespacedName) WatcherTestData {
Namespace: watcherName.Namespace,
Name: fmt.Sprintf("%s-db-sync", watcherName.Name),
},
WatcherAPIDeployment: types.NamespacedName{
Namespace: watcherName.Namespace,
Name: "watcher-api-api",
},
}
}
25 changes: 25 additions & 0 deletions tests/functional/watcherapi_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,31 @@ var _ = Describe("WatcherAPI controller", func() {
corev1.ConditionTrue,
)
})
It("creates a deployment for the watcher-api service", func() {
th.ExpectCondition(
watcherTest.WatcherAPI,
ConditionGetterFunc(WatcherAPIConditionGetter),
condition.DeploymentReadyCondition,
corev1.ConditionTrue,
)

deployment := th.GetDeployment(watcherTest.WatcherAPIDeployment)
Expect(deployment.Spec.Template.Spec.ServiceAccountName).To(Equal("watcher-sa"))
Expect(int(*deployment.Spec.Replicas)).To(Equal(1))
Expect(deployment.Spec.Template.Spec.Volumes).To(HaveLen(3))
Expect(deployment.Spec.Template.Spec.Containers).To(HaveLen(2))

container := deployment.Spec.Template.Spec.Containers[0]
Expect(container.VolumeMounts).To(HaveLen(1))
Expect(container.Image).To(Equal("test://watcher"))

container = deployment.Spec.Template.Spec.Containers[1]
Expect(container.VolumeMounts).To(HaveLen(4))
Expect(container.Image).To(Equal("test://watcher"))

Expect(container.LivenessProbe.HTTPGet.Port.IntVal).To(Equal(int32(9322)))
Expect(container.ReadinessProbe.HTTPGet.Port.IntVal).To(Equal(int32(9322)))
})
})
When("the secret is created but missing fields", func() {
BeforeEach(func() {
Expand Down
31 changes: 31 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 @@ -16,6 +16,10 @@ status:
reason: Ready
status: "True"
type: Ready
- message: Deployment completed
reason: Ready
status: "True"
type: DeploymentReady
- message: Input data complete
reason: Ready
status: "True"
Expand All @@ -34,3 +38,30 @@ kind: Secret
metadata:
name: watcherapi-kuttl-config-data
type: Opaque
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: watcherapi-kuttl-api
spec:
replicas: 1
template:
spec:
containers:
- name: watcherapi-kuttl-log
- name: watcher-api
status:
readyReplicas: 1
replicas: 1
---
apiVersion: v1
kind: Pod
metadata:
labels:
watcher.openstack.org/name: watcherapi-kuttl
spec:
containers:
- name: watcherapi-kuttl-log
- name: watcher-api
status:
phase: Running
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ spec:
databaseInstance: openstack
secret: watcherapi-secret
memcachedInstance: "memcached"
containerImage: "quay.io/podified-antelope-centos9/openstack-watcher-api:current-podified"
serviceAccount: watcher-watcher-kuttl
15 changes: 15 additions & 0 deletions tests/kuttl/test-suites/default/watcher-api/05-errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: watcher.openstack.org/v1beta1
kind: WatcherAPI
metadata:
name: watcherapi-kuttl
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: watcherapi-kuttl-api
---
apiVersion: v1
kind: Pod
metadata:
labels:
watcher.openstack.org/name: watcherapi-kuttl

0 comments on commit 1d7124b

Please sign in to comment.