From c0f26e4b47b36e300930b3178b4a5606a26a39c1 Mon Sep 17 00:00:00 2001 From: Peter Motzko Date: Tue, 27 Jun 2023 10:40:21 +0200 Subject: [PATCH] feat(test): add Helm unittests for default values --- Taskfile.yaml | 2 +- .../tests/default_deployment_test.yaml | 97 +++++++++++++++++++ .../tests/default_service_account_test.yaml | 41 ++++++++ .../tests/default_service_test.yaml | 59 +++++++++++ .../tests/deployment_default_test.yaml | 14 --- 5 files changed, 198 insertions(+), 15 deletions(-) create mode 100644 charts/managed-identity-wallet/tests/default_deployment_test.yaml create mode 100644 charts/managed-identity-wallet/tests/default_service_account_test.yaml create mode 100644 charts/managed-identity-wallet/tests/default_service_test.yaml delete mode 100644 charts/managed-identity-wallet/tests/deployment_default_test.yaml diff --git a/Taskfile.yaml b/Taskfile.yaml index 6a50c6f4d..46af43677 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -39,7 +39,7 @@ tasks: desc: Executes helm unittests dir: charts/managed-identity-wallet cmds: - - helm unittest -f tests/**/*_test.yaml . + - helm unittest . build-app: desc: Build the whole app diff --git a/charts/managed-identity-wallet/tests/default_deployment_test.yaml b/charts/managed-identity-wallet/tests/default_deployment_test.yaml new file mode 100644 index 000000000..b6b8a2efe --- /dev/null +++ b/charts/managed-identity-wallet/tests/default_deployment_test.yaml @@ -0,0 +1,97 @@ +# /******************************************************************************** +# * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation +# * +# * See the NOTICE file(s) distributed with this work for additional +# * information regarding copyright ownership. +# * +# * This program and the accompanying materials are made available under the +# * terms of the Apache License, Version 2.0 which is available at +# * https://www.apache.org/licenses/LICENSE-2.0. +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# * License for the specific language governing permissions and limitations +# * under the License. +# * +# * SPDX-License-Identifier: Apache-2.0 +# ********************************************************************************/ + +suite: test default deployment +chart: + version: 9.9.9+test + appVersion: 9.9.9 +tests: + - it: should have correct metadata + template: templates/deployment.yaml + asserts: + - hasDocuments: + count: 1 + - containsDocument: + kind: Deployment + apiVersion: apps/v1 + name: RELEASE-NAME-managed-identity-wallet + - isSubset: + path: metadata.labels + content: + helm.sh/chart: managed-identity-wallet-9.9.9_test + app.kubernetes.io/name: managed-identity-wallet + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/version: "9.9.9" + app.kubernetes.io/managed-by: Helm + + - it: must have important values set + template: templates/deployment.yaml + asserts: + - equal: + path: spec.replicas + value: 1 + - lengthEqual: + path: spec.template.spec.containers + count: 1 + - isNotEmpty: + path: spec.template.spec.serviceAccountName + - contains: + path: spec.template.spec.containers[0].ports + content: + name: http + containerPort: 8080 + protocol: TCP + + - it: must have probes set + template: templates/deployment.yaml + asserts: + - isNotEmpty: + path: spec.template.spec.containers[0].livenessProbe + - isNotEmpty: + path: spec.template.spec.containers[0].readinessProbe + + - it: must have resource limits set + template: templates/deployment.yaml + asserts: + - isNotEmpty: + path: spec.template.spec.containers[0].resources + - isNotEmpty: + path: spec.template.spec.containers[0].resources.limits + - isNotEmpty: + path: spec.template.spec.containers[0].resources.limits.cpu + - isNotEmpty: + path: spec.template.spec.containers[0].resources.limits.memory + - isNotEmpty: + path: spec.template.spec.containers[0].resources.requests + - isNotEmpty: + path: spec.template.spec.containers[0].resources.requests.cpu + - isNotEmpty: + path: spec.template.spec.containers[0].resources.requests.memory + + - it: must have a security context + template: templates/deployment.yaml + asserts: + - isSubset: + path: spec.template.spec.containers[0].securityContext + content: + allowPrivilegeEscalation: false + privileged: false + runAsGroup: 11111 + runAsNonRoot: true + runAsUser: 11111 \ No newline at end of file diff --git a/charts/managed-identity-wallet/tests/default_service_account_test.yaml b/charts/managed-identity-wallet/tests/default_service_account_test.yaml new file mode 100644 index 000000000..01f127da5 --- /dev/null +++ b/charts/managed-identity-wallet/tests/default_service_account_test.yaml @@ -0,0 +1,41 @@ +# /******************************************************************************** +# * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation +# * +# * See the NOTICE file(s) distributed with this work for additional +# * information regarding copyright ownership. +# * +# * This program and the accompanying materials are made available under the +# * terms of the Apache License, Version 2.0 which is available at +# * https://www.apache.org/licenses/LICENSE-2.0. +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# * License for the specific language governing permissions and limitations +# * under the License. +# * +# * SPDX-License-Identifier: Apache-2.0 +# ********************************************************************************/ + +suite: test default serviceaccount +chart: + version: 9.9.9+test + appVersion: 9.9.9 +tests: + - it: should have correct metadata + template: templates/serviceaccount.yaml + asserts: + - hasDocuments: + count: 1 + - containsDocument: + kind: ServiceAccount + apiVersion: v1 + name: RELEASE-NAME-managed-identity-wallet + - isSubset: + path: metadata.labels + content: + helm.sh/chart: managed-identity-wallet-9.9.9_test + app.kubernetes.io/name: managed-identity-wallet + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/version: "9.9.9" + app.kubernetes.io/managed-by: Helm \ No newline at end of file diff --git a/charts/managed-identity-wallet/tests/default_service_test.yaml b/charts/managed-identity-wallet/tests/default_service_test.yaml new file mode 100644 index 000000000..0681b52e4 --- /dev/null +++ b/charts/managed-identity-wallet/tests/default_service_test.yaml @@ -0,0 +1,59 @@ +# /******************************************************************************** +# * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation +# * +# * See the NOTICE file(s) distributed with this work for additional +# * information regarding copyright ownership. +# * +# * This program and the accompanying materials are made available under the +# * terms of the Apache License, Version 2.0 which is available at +# * https://www.apache.org/licenses/LICENSE-2.0. +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# * License for the specific language governing permissions and limitations +# * under the License. +# * +# * SPDX-License-Identifier: Apache-2.0 +# ********************************************************************************/ + +suite: test default service +chart: + version: 9.9.9+test + appVersion: 9.9.9 +tests: + - it: should have correct metadata + template: templates/service.yaml + asserts: + - hasDocuments: + count: 1 + - containsDocument: + kind: Service + apiVersion: v1 + name: RELEASE-NAME-managed-identity-wallet + - isSubset: + path: metadata.labels + content: + helm.sh/chart: managed-identity-wallet-9.9.9_test + app.kubernetes.io/name: managed-identity-wallet + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/version: "9.9.9" + app.kubernetes.io/managed-by: Helm + + - it: must have type set to ClusterIP + template: templates/service.yaml + asserts: + - equal: + path: spec.type + value: ClusterIP + + - it: must have ports set + template: templates/service.yaml + asserts: + - contains: + path: spec.ports + content: + name: http + targetPort: http + port: 8080 + protocol: TCP \ No newline at end of file diff --git a/charts/managed-identity-wallet/tests/deployment_default_test.yaml b/charts/managed-identity-wallet/tests/deployment_default_test.yaml deleted file mode 100644 index 998a16691..000000000 --- a/charts/managed-identity-wallet/tests/deployment_default_test.yaml +++ /dev/null @@ -1,14 +0,0 @@ -suite: test default deployment -chart: - version: 9.9.9+test - appVersion: 9.9.9 -tests: - - it: should have correct metadata - template: templates/deployment.yaml - asserts: - - hasDocuments: - count: 1 - - isAPIVersion: - of: apps/v1 - - isKind: - of: Deployment \ No newline at end of file