From 1ffd73b5cff0a3ad5dee367789c6f47f5a3846e1 Mon Sep 17 00:00:00 2001 From: mway-niels <53857383+mway-niels@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:56:03 +0700 Subject: [PATCH] Added Helm unit tests (#15) * Updated GitHub Workflow * Added initial unit tests * Bumped chart version --- .github/workflows/lint-test.yaml | 12 +++++ charts/relution/Chart.yaml | 2 +- charts/relution/ci/full.yaml | 45 +++++++++++++++++++ charts/relution/tests/config_test.yaml | 11 +++++ charts/relution/tests/deployment_test.yaml | 23 ++++++++++ .../tests/ensure_helm_labels_test.yaml | 21 +++++++++ charts/relution/tests/environment_test.yaml | 11 +++++ charts/relution/tests/secrets_test.yaml | 11 +++++ 8 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 charts/relution/ci/full.yaml create mode 100644 charts/relution/tests/config_test.yaml create mode 100644 charts/relution/tests/deployment_test.yaml create mode 100644 charts/relution/tests/ensure_helm_labels_test.yaml create mode 100644 charts/relution/tests/environment_test.yaml create mode 100644 charts/relution/tests/secrets_test.yaml diff --git a/.github/workflows/lint-test.yaml b/.github/workflows/lint-test.yaml index 9f0ace8..e65fd2c 100644 --- a/.github/workflows/lint-test.yaml +++ b/.github/workflows/lint-test.yaml @@ -28,6 +28,14 @@ jobs: - name: Set up chart-testing uses: helm/chart-testing-action@v2.6.1 + - name: Set up helm-unittest + run: | + helm plugin install https://github.com/helm-unittest/helm-unittest + + - name: Install subchart dependencies + run: | + helm dependency build ./charts/relution + - name: Run chart-testing (list-changed) id: list-changed run: | @@ -40,6 +48,10 @@ jobs: if: steps.list-changed.outputs.changed == 'true' run: ct lint --target-branch ${{ github.event.repository.default_branch }} + - name: Run helm-unittest + run: | + helm unittest ./charts/relution + - name: Create kind cluster if: steps.list-changed.outputs.changed == 'true' uses: helm/kind-action@v1.9.0 diff --git a/charts/relution/Chart.yaml b/charts/relution/Chart.yaml index 603f0ff..7013220 100644 --- a/charts/relution/Chart.yaml +++ b/charts/relution/Chart.yaml @@ -8,7 +8,7 @@ maintainers: type: application -version: 2.2.5-3 +version: 2.2.6-1 appVersion: "5.22.3" diff --git a/charts/relution/ci/full.yaml b/charts/relution/ci/full.yaml new file mode 100644 index 0000000..e8313e0 --- /dev/null +++ b/charts/relution/ci/full.yaml @@ -0,0 +1,45 @@ +ingress: + enabled: true + hosts: + - host: "test.relution.io" + paths: + - path: / + pathType: ImplementationSpecific + +relution: + preRunScript: | + #!/bin/bash + echo "Prerun script ran." > /tmp/prerun.txt + config: + relution: + database: + type: mariadb + url: jdbc:mariadb://mariadb:3306/relution + username: relution + password: relution + environment: + RELUTION_SERVER_EXTERNALURL: https://test.relution.io + RELUTION_DATABASE_TYPE: mariadb + RELUTION_DATABASE_URL: jdbc:mariadb://mariadb:3306/relution + RELUTION_DATABASE_USERNAME: relution + secrets: + RELUTION_DATABASE_PASSWORD: relution + +autoscaling: + enabled: true + +heapDumpExporter: + enabled: true + s3: + bucket: s3://test-relution-io + awsAccessKeyId: relution + awsSecretAccessKey: relution + +mariadb: + enabled: true + fullnameOverride: mariadb + auth: + rootPassword: relution + username: relution + password: relution + database: relution diff --git a/charts/relution/tests/config_test.yaml b/charts/relution/tests/config_test.yaml new file mode 100644 index 0000000..22f913b --- /dev/null +++ b/charts/relution/tests/config_test.yaml @@ -0,0 +1,11 @@ +suite: test config +values: + - ../ci/minimal-values.yaml +templates: + - config.yaml +tests: + - it: should work + asserts: + - template: config.yaml + isKind: + of: ConfigMap diff --git a/charts/relution/tests/deployment_test.yaml b/charts/relution/tests/deployment_test.yaml new file mode 100644 index 0000000..3dd3ae1 --- /dev/null +++ b/charts/relution/tests/deployment_test.yaml @@ -0,0 +1,23 @@ +suite: test deployment +values: + - ../ci/minimal-values.yaml +templates: + - deployment.yaml + - config.yaml +tests: + - it: should work + set: + image.tag: latest + imageMagick.enabled: false + asserts: + - template: deployment.yaml + isKind: + of: Deployment + - template: deployment.yaml + matchRegex: + path: metadata.name + pattern: -relution$ + - template: deployment.yaml + equal: + path: spec.template.spec.containers[0].image + value: relution/relution:latest diff --git a/charts/relution/tests/ensure_helm_labels_test.yaml b/charts/relution/tests/ensure_helm_labels_test.yaml new file mode 100644 index 0000000..646253e --- /dev/null +++ b/charts/relution/tests/ensure_helm_labels_test.yaml @@ -0,0 +1,21 @@ +suite: helm labels +values: + - ../ci/full.yaml +templates: + - "*.yaml" +tests: + - it: should contain default helm labels + set: + mariadb: + enabled: false + asserts: + - exists: + path: metadata.labels['helm.sh/chart'] + - exists: + path: metadata.labels['app.kubernetes.io/version'] + - exists: + path: metadata.labels['app.kubernetes.io/managed-by'] + - exists: + path: metadata.labels['app.kubernetes.io/name'] + - exists: + path: metadata.labels['app.kubernetes.io/instance'] diff --git a/charts/relution/tests/environment_test.yaml b/charts/relution/tests/environment_test.yaml new file mode 100644 index 0000000..a550590 --- /dev/null +++ b/charts/relution/tests/environment_test.yaml @@ -0,0 +1,11 @@ +suite: test environment +values: + - ../ci/full.yaml +templates: + - environment.yaml +tests: + - it: should work + asserts: + - template: environment.yaml + isKind: + of: ConfigMap diff --git a/charts/relution/tests/secrets_test.yaml b/charts/relution/tests/secrets_test.yaml new file mode 100644 index 0000000..3da2416 --- /dev/null +++ b/charts/relution/tests/secrets_test.yaml @@ -0,0 +1,11 @@ +suite: test secrets +values: + - ../ci/full.yaml +templates: + - secrets.yaml +tests: + - it: should work + asserts: + - template: secrets.yaml + isKind: + of: Secret