From 5edc729df2655452d9ca21c15c9d4a23788e87e0 Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Wed, 3 Apr 2024 16:06:17 +0200 Subject: [PATCH] OZG-3328 helm unittest cleanup and add tests to cover fully cover helm charts --- .../helm/configmap_bindings_type_test.yaml | 2 + .../test/helm/deployment_container_test.yaml | 20 +++------- ...ml => deployment_env_customList_test.yaml} | 0 .../test/helm/deployment_metadata_test.yaml | 40 +++++++------------ .../test/helm/deployment_resources_test.yaml | 14 +++---- .../helm/deployment_template_spec_test.yaml | 36 +++++++++-------- .../src/test/helm/deployment_type_test.yaml | 10 ++--- ...umes.yaml => deployment_volumes_test.yaml} | 25 ++++-------- .../src/test/helm/linter_values.yaml | 4 -- ...icsearch_operator_serviceaccount_test.yaml | 2 + 10 files changed, 61 insertions(+), 92 deletions(-) rename ozgcloud-elasticsearch-operator/src/test/helm/{deployment_env_test.yaml => deployment_env_customList_test.yaml} (100%) rename ozgcloud-elasticsearch-operator/src/test/helm/{deployment_volumes.yaml => deployment_volumes_test.yaml} (86%) diff --git a/ozgcloud-elasticsearch-operator/src/test/helm/configmap_bindings_type_test.yaml b/ozgcloud-elasticsearch-operator/src/test/helm/configmap_bindings_type_test.yaml index 83ece1c..874ac81 100644 --- a/ozgcloud-elasticsearch-operator/src/test/helm/configmap_bindings_type_test.yaml +++ b/ozgcloud-elasticsearch-operator/src/test/helm/configmap_bindings_type_test.yaml @@ -32,6 +32,8 @@ tests: asserts: - isKind: of: ConfigMap + - isAPIVersion: + of: v1 - equal: path: metadata.name value: bindings-type diff --git a/ozgcloud-elasticsearch-operator/src/test/helm/deployment_container_test.yaml b/ozgcloud-elasticsearch-operator/src/test/helm/deployment_container_test.yaml index 462e66f..56ca883 100644 --- a/ozgcloud-elasticsearch-operator/src/test/helm/deployment_container_test.yaml +++ b/ozgcloud-elasticsearch-operator/src/test/helm/deployment_container_test.yaml @@ -28,13 +28,13 @@ release: namespace: sh-helm-test templates: - deployment.yaml +set: + image: + name: hase + tag: latest + imagePullSecret: imagePullSecret tests: - it: validate image type and container image - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - equal: path: spec.template.spec.containers[0].name @@ -47,11 +47,6 @@ tests: value: Always - it: validate health checks - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - equal: path: spec.template.spec.containers[0].readinessProbe @@ -78,11 +73,6 @@ tests: timeoutSeconds: 5 - it: validate security context - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - equal: path: spec.template.spec.containers[0].securityContext diff --git a/ozgcloud-elasticsearch-operator/src/test/helm/deployment_env_test.yaml b/ozgcloud-elasticsearch-operator/src/test/helm/deployment_env_customList_test.yaml similarity index 100% rename from ozgcloud-elasticsearch-operator/src/test/helm/deployment_env_test.yaml rename to ozgcloud-elasticsearch-operator/src/test/helm/deployment_env_customList_test.yaml diff --git a/ozgcloud-elasticsearch-operator/src/test/helm/deployment_metadata_test.yaml b/ozgcloud-elasticsearch-operator/src/test/helm/deployment_metadata_test.yaml index fa56624..d39d576 100644 --- a/ozgcloud-elasticsearch-operator/src/test/helm/deployment_metadata_test.yaml +++ b/ozgcloud-elasticsearch-operator/src/test/helm/deployment_metadata_test.yaml @@ -28,42 +28,30 @@ release: namespace: sh-helm-test templates: - templates/deployment.yaml +set: + image: + name: hase + tag: latest + imagePullSecret: imagePullSecret tests: - it: check metadata labels - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - equal: - path: metadata.labels["app.kubernetes.io/instance"] - value: ozgcloud-elasticsearch-operator - - equal: - path: metadata.labels["app.kubernetes.io/name"] - value: ozgcloud-elasticsearch-operator - - equal: - path: metadata.labels["app.kubernetes.io/part-of"] - value: ozg - - equal: - path: metadata.labels["app.kubernetes.io/namespace"] - value: sh-helm-test + path: metadata.labels + value: + app.kubernetes.io/instance: ozgcloud-elasticsearch-operator + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: ozgcloud-elasticsearch-operator + app.kubernetes.io/namespace: sh-helm-test + app.kubernetes.io/part-of: ozg + app.kubernetes.io/version: 0.0.0-MANAGED-BY-JENKINS + helm.sh/chart: ozgcloud-elasticsearch-operator-0.0.0-MANAGED-BY-JENKINS - it: check metadata name - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - equal: path: metadata.name value: ozgcloud-elasticsearch-operator - it: check metadata namespace - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - equal: path: metadata.namespace diff --git a/ozgcloud-elasticsearch-operator/src/test/helm/deployment_resources_test.yaml b/ozgcloud-elasticsearch-operator/src/test/helm/deployment_resources_test.yaml index 5e871d2..cff78ba 100644 --- a/ozgcloud-elasticsearch-operator/src/test/helm/deployment_resources_test.yaml +++ b/ozgcloud-elasticsearch-operator/src/test/helm/deployment_resources_test.yaml @@ -27,6 +27,11 @@ release: name: afm-adapter templates: - templates/deployment.yaml +set: + image: + name: hase + tag: latest + imagePullSecret: imagePullSecret tests: - it: test resources set: @@ -37,10 +42,6 @@ tests: requests: cpu: "33m" memory: "44Mi" - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - equal: path: spec.template.spec.containers[0].resources.limits.cpu @@ -56,11 +57,6 @@ tests: value: 44Mi - it: test empty resources - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - isEmpty: path: spec.template.spec.containers[0].resources diff --git a/ozgcloud-elasticsearch-operator/src/test/helm/deployment_template_spec_test.yaml b/ozgcloud-elasticsearch-operator/src/test/helm/deployment_template_spec_test.yaml index 8ec9dba..1aa878d 100644 --- a/ozgcloud-elasticsearch-operator/src/test/helm/deployment_template_spec_test.yaml +++ b/ozgcloud-elasticsearch-operator/src/test/helm/deployment_template_spec_test.yaml @@ -28,39 +28,43 @@ release: namespace: sh-helm-test templates: - deployment.yaml +set: + image: + name: hase + tag: latest + imagePullSecret: imagePullSecret tests: - it: validate serviceaccount name - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - equal: path: spec.template.spec.serviceAccountName value: ozgcloud-elasticsearch-operator-serviceaccount - it: validate restartPolicy - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - equal: path: spec.template.spec.restartPolicy value: Always - it: validate dns config - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - equal: path: spec.template.spec.dnsConfig value: {} - equal: path: spec.template.spec.dnsPolicy - value: ClusterFirst \ No newline at end of file + value: ClusterFirst + - it: should have correct values for container terminationMessagePolicy, terminationMessagePath, stdin, tty + asserts: + - equal: + path: spec.template.spec.containers[0].terminationMessagePolicy + value: File + - equal: + path: spec.template.spec.containers[0].terminationMessagePath + value: /dev/termination-log + - equal: + path: spec.template.spec.containers[0].stdin + value: true + - equal: + path: spec.template.spec.containers[0].tty + value: true \ No newline at end of file diff --git a/ozgcloud-elasticsearch-operator/src/test/helm/deployment_type_test.yaml b/ozgcloud-elasticsearch-operator/src/test/helm/deployment_type_test.yaml index e992e29..8216a62 100644 --- a/ozgcloud-elasticsearch-operator/src/test/helm/deployment_type_test.yaml +++ b/ozgcloud-elasticsearch-operator/src/test/helm/deployment_type_test.yaml @@ -28,13 +28,13 @@ release: namespace: sh-helm-test templates: - deployment.yaml +set: + image: + name: hase + tag: latest + imagePullSecret: imagePullSecret tests: - it: validate template type and api Version - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - isKind: of: Deployment diff --git a/ozgcloud-elasticsearch-operator/src/test/helm/deployment_volumes.yaml b/ozgcloud-elasticsearch-operator/src/test/helm/deployment_volumes_test.yaml similarity index 86% rename from ozgcloud-elasticsearch-operator/src/test/helm/deployment_volumes.yaml rename to ozgcloud-elasticsearch-operator/src/test/helm/deployment_volumes_test.yaml index 15ce39b..db2cdd1 100644 --- a/ozgcloud-elasticsearch-operator/src/test/helm/deployment_volumes.yaml +++ b/ozgcloud-elasticsearch-operator/src/test/helm/deployment_volumes_test.yaml @@ -22,19 +22,20 @@ # unter der Lizenz sind dem Lizenztext zu entnehmen. # -suite: deployment type test +suite: deployment volumes test release: name: elastic-test-operator namespace: sh-helm-test templates: - - deployment.yaml + - templates/deployment.yaml + +set: + image: + name: hase + tag: latest + imagePullSecret: imagePullSecret tests: - it: should create SERVICE_BINDING_ROOT - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - contains: path: spec.template.spec.containers[0].env @@ -43,11 +44,6 @@ tests: value: "/bindings" - it: should create volumes - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - contains: path: spec.template.spec.volumes @@ -64,11 +60,6 @@ tests: optional: false - it: should create volumeMounts - set: - image: - name: hase - tag: latest - imagePullSecret: imagePullSecret asserts: - contains: path: spec.template.spec.containers[0].volumeMounts diff --git a/ozgcloud-elasticsearch-operator/src/test/helm/linter_values.yaml b/ozgcloud-elasticsearch-operator/src/test/helm/linter_values.yaml index aab55ac..a27fd79 100644 --- a/ozgcloud-elasticsearch-operator/src/test/helm/linter_values.yaml +++ b/ozgcloud-elasticsearch-operator/src/test/helm/linter_values.yaml @@ -5,7 +5,3 @@ image: imagePullSecret: "docker-secret" -env: - customList: - - name: my_test_environment_name - value: "A test value" \ No newline at end of file diff --git a/ozgcloud-elasticsearch-operator/src/test/helm/rbac/ozgcloud_elasticsearch_operator_serviceaccount_test.yaml b/ozgcloud-elasticsearch-operator/src/test/helm/rbac/ozgcloud_elasticsearch_operator_serviceaccount_test.yaml index c2a93ca..e52b668 100644 --- a/ozgcloud-elasticsearch-operator/src/test/helm/rbac/ozgcloud_elasticsearch_operator_serviceaccount_test.yaml +++ b/ozgcloud-elasticsearch-operator/src/test/helm/rbac/ozgcloud_elasticsearch_operator_serviceaccount_test.yaml @@ -33,6 +33,8 @@ tests: asserts: - isKind: of: ServiceAccount + - isAPIVersion: + of: v1 - equal: path: metadata.name value: ozgcloud-elasticsearch-operator-serviceaccount -- GitLab