From 4d90e8a3dd067992ce1f8ac17ee04c34ec855225 Mon Sep 17 00:00:00 2001 From: Rob Holland Date: Thu, 21 Nov 2024 16:44:33 +0000 Subject: [PATCH] Add some unit tests. (#610) * Add some unit tests. These are more succinct and much faster than the terratest tests. --- .github/workflows/ci.yml | 9 +++- charts/temporal/.helmignore | 1 + .../tests/server_deployment_test.yaml | 54 +++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 charts/temporal/tests/server_deployment_test.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3bd71b70..501598a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,4 +49,11 @@ jobs: - name: Run template tests working-directory: charts/temporal/tests - run: go test \ No newline at end of file + run: go test + + - name: Install helm-unittest + run: helm plugin install https://github.com/helm-unittest/helm-unittest.git + + - name: Run helm-unittest + working-directory: charts/temporal + run: helm unittest . diff --git a/charts/temporal/.helmignore b/charts/temporal/.helmignore index 50af0317..f85b0ee2 100644 --- a/charts/temporal/.helmignore +++ b/charts/temporal/.helmignore @@ -20,3 +20,4 @@ .idea/ *.tmproj .vscode/ +tests/ diff --git a/charts/temporal/tests/server_deployment_test.yaml b/charts/temporal/tests/server_deployment_test.yaml new file mode 100644 index 00000000..3c4d5557 --- /dev/null +++ b/charts/temporal/tests/server_deployment_test.yaml @@ -0,0 +1,54 @@ +suite: test server deployment +templates: + - server-deployment.yaml + - server-configmap.yaml +set: + server: + replicaCount: 2 + resources: + requests: + cpu: 100m + frontend: + replicaCount: 3 + resources: + requests: + cpu: 200m +tests: + - it: defaults to service wide replica count + template: templates/server-deployment.yaml + documentSelector: + path: '$[?(@.metadata.name != "RELEASE-NAME-temporal-frontend")].kind' + value: Deployment + matchMany: true + asserts: + - equal: + path: spec.replicas + value: 2 + - it: favours service specific replica count + template: templates/server-deployment.yaml + documentSelector: + path: metadata.name + value: RELEASE-NAME-temporal-frontend + asserts: + - equal: + path: spec.replicas + value: 3 + - it: defaults to service wide resources + template: templates/server-deployment.yaml + documentSelector: + path: '$[?(@.metadata.name != "RELEASE-NAME-temporal-frontend")].kind' + value: Deployment + matchMany: true + asserts: + - equal: + path: spec.template.spec.containers[0].resources.requests.cpu + value: 100m + - it: favours service specific resources + template: templates/server-deployment.yaml + documentSelector: + path: metadata.name + value: RELEASE-NAME-temporal-frontend + asserts: + - equal: + path: spec.template.spec.containers[0].resources.requests.cpu + value: 200m