From c3f14c54e7a070fce7d583706818622bf4e22861 Mon Sep 17 00:00:00 2001 From: Federico Feresini Date: Fri, 15 Sep 2023 09:06:42 +0200 Subject: [PATCH] add unittest --- .../cluster-scanner/templates/deployment.yaml | 8 ++--- .../tests/deployment_test.yaml | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/charts/cluster-scanner/templates/deployment.yaml b/charts/cluster-scanner/templates/deployment.yaml index 2d12d0e26..21abcd57d 100644 --- a/charts/cluster-scanner/templates/deployment.yaml +++ b/charts/cluster-scanner/templates/deployment.yaml @@ -281,10 +281,6 @@ spec: - name: "{{ $key }}" value: "{{ $value }}" {{- end }} - {{- range $key, $value := .Values.imageSbomExtractor.env }} - - name: "{{ $key }}" - value: "{{ $value }}" - {{- end }} {{- with .Values.runtimeStatusIntegrator }} livenessProbe: httpGet: @@ -544,6 +540,10 @@ spec: key: cache_redis_ttl optional: true {{- end }} + {{- range $key, $value := .Values.imageSbomExtractor.env }} + - name: "{{ $key }}" + value: "{{ $value }}" + {{- end }} {{- with .Values.imageSbomExtractor }} resources: {{- toYaml .resources | nindent 12 }} diff --git a/charts/cluster-scanner/tests/deployment_test.yaml b/charts/cluster-scanner/tests/deployment_test.yaml index 4f1cb3c4a..3489b5795 100644 --- a/charts/cluster-scanner/tests/deployment_test.yaml +++ b/charts/cluster-scanner/tests/deployment_test.yaml @@ -440,3 +440,35 @@ tests: content: name: PPROF_PORT value: "666" + + - it: "sets optional envs" + templates: + - ../templates/deployment.yaml + set: + runtimeStatusIntegrator.env: { ENV_VAR_STRING: "test", ENV_VAR_NUM: 15 } + imageSbomExtractor.env: { ENV_VAR_BOOL: true } + asserts: + - not: true + isEmpty: + path: spec.template.spec.containers[0].env[?(@.name == "ENV_VAR_STRING")] + - isSubset: + path: spec.template.spec.containers[0].env[?(@.name == "ENV_VAR_STRING")] + content: + name: ENV_VAR_STRING + value: "test" + - not: true + isEmpty: + path: spec.template.spec.containers[0].env[?(@.name == "ENV_VAR_NUM")] + - isSubset: + path: spec.template.spec.containers[0].env[?(@.name == "ENV_VAR_NUM")] + content: + name: ENV_VAR_NUM + value: "15" + - not: true + isEmpty: + path: spec.template.spec.containers[1].env[?(@.name == "ENV_VAR_BOOL")] + - isSubset: + path: spec.template.spec.containers[1].env[?(@.name == "ENV_VAR_BOOL")] + content: + name: ENV_VAR_BOOL + value: "true"