From cdbd064a1372d4351b97658aa636f83c0d8b4482 Mon Sep 17 00:00:00 2001 From: Hayden Spitzley <105455169+hspitzley-czi@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:15:14 -0700 Subject: [PATCH] chore: add tests for HPA (#171) --- stack/tests/deployment_test.yaml | 23 ++++++++++++++++++++++- stack/tests/hpa_test.yaml | 27 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 stack/tests/hpa_test.yaml diff --git a/stack/tests/deployment_test.yaml b/stack/tests/deployment_test.yaml index 41e8bbf..ede0e06 100644 --- a/stack/tests/deployment_test.yaml +++ b/stack/tests/deployment_test.yaml @@ -31,11 +31,32 @@ tests: path: spec content: revisionHistoryLimit: 3 - any: true - containsDocument: apiVersion: apps/v1 kind: Deployment + - it: sets replicas when autoscaling is disabled + set: + services: + service1: + autoscaling: + enabled: false + replicaCount: 2 + asserts: + - equal: + path: spec.replicas + value: 2 + - it: does not set replicas when autoscaling is enabled + set: + services: + service1: + autoscaling: + enabled: true + replicaCount: 2 + asserts: + - notExists: + path: spec.replicas + - it: uses httpGet probe by default set: services: diff --git a/stack/tests/hpa_test.yaml b/stack/tests/hpa_test.yaml new file mode 100644 index 0000000..7cf6ca1 --- /dev/null +++ b/stack/tests/hpa_test.yaml @@ -0,0 +1,27 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: test HorizontalPodAutoscaler +templates: + - hpa.yaml +tests: + - it: should work + set: + services: + service1: + args: ["arg1", "arg2"] + command: ["command1", "command2"] + autoscaling: + enabled: true + minReplicas: 2 + maxReplicas: 10 + maxUnavailable: 1 + replicaCount: 2 # this should be ignored when autoscaling is enabled + asserts: + - containsDocument: + apiVersion: autoscaling/v2 + kind: HorizontalPodAutoscaler + - equal: + path: spec.minReplicas + value: 2 + - equal: + path: spec.maxReplicas + value: 10