From feec4021dc4f5234c2ca30c51c82849d9066b70f Mon Sep 17 00:00:00 2001 From: Simon Baeumer Date: Tue, 25 Jan 2022 10:05:12 +0100 Subject: [PATCH 1/3] X-Smart-Branch-Parent: add-integration-tests From 6e8da0dbff7245b993ba86fd6433f2fa17454e40 Mon Sep 17 00:00:00 2001 From: Simon Baeumer Date: Tue, 25 Jan 2022 10:05:33 +0100 Subject: [PATCH 2/3] Add def function test --- integration_test/integration_test.go | 2 +- .../helmtest/additional_directory/inhereit_defines.test.yaml | 4 ++++ integration_test/testdata/helmtest/suite.yaml | 3 +++ .../testdata/nginx-example/templates/deployment.yaml | 2 +- integration_test/testdata/nginx-example/values.yaml | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 integration_test/testdata/helmtest/additional_directory/inhereit_defines.test.yaml diff --git a/integration_test/integration_test.go b/integration_test/integration_test.go index 041dcca..f5b73bd 100644 --- a/integration_test/integration_test.go +++ b/integration_test/integration_test.go @@ -9,7 +9,7 @@ import ( ) func TestHelmTestShouldSucceed(t *testing.T) { - l := framework.NewLoader("testdata/helmtest") + l := framework.NewLoader("testdata/helmtest", framework.WithAdditionalTestDirs("testdata/helmtest/additional_directory")) s, err := l.LoadSuite() require.NoError(t, err) diff --git a/integration_test/testdata/helmtest/additional_directory/inhereit_defines.test.yaml b/integration_test/testdata/helmtest/additional_directory/inhereit_defines.test.yaml new file mode 100644 index 0000000..369e2c4 --- /dev/null +++ b/integration_test/testdata/helmtest/additional_directory/inhereit_defines.test.yaml @@ -0,0 +1,4 @@ +tests: + - name: "use defined function" + expect: + container(.deployments.nginx, nginx) | assertThat(. != null) diff --git a/integration_test/testdata/helmtest/suite.yaml b/integration_test/testdata/helmtest/suite.yaml index b6e02b3..2b4257b 100644 --- a/integration_test/testdata/helmtest/suite.yaml +++ b/integration_test/testdata/helmtest/suite.yaml @@ -1,3 +1,6 @@ +defs: | + def container(obj; name): + obj.spec.template.spec.containers[] | select(.name == name); server: visibleSchemas: - kubernetes-1.20.2 diff --git a/integration_test/testdata/nginx-example/templates/deployment.yaml b/integration_test/testdata/nginx-example/templates/deployment.yaml index 71f128d..2145331 100644 --- a/integration_test/testdata/nginx-example/templates/deployment.yaml +++ b/integration_test/testdata/nginx-example/templates/deployment.yaml @@ -28,7 +28,7 @@ spec: securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: - - name: {{ .Chart.Name }} + - name: nginx securityContext: {{- toYaml .Values.securityContext | nindent 12 }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" diff --git a/integration_test/testdata/nginx-example/values.yaml b/integration_test/testdata/nginx-example/values.yaml index 1e6e960..4f665f3 100644 --- a/integration_test/testdata/nginx-example/values.yaml +++ b/integration_test/testdata/nginx-example/values.yaml @@ -12,7 +12,7 @@ image: imagePullSecrets: [] nameOverride: "" -fullnameOverride: "" +fullnameOverride: "nginx" serviceAccount: # Specifies whether a service account should be created From 8b9eadf86184874c2150be8890bd54d80e0ee737 Mon Sep 17 00:00:00 2001 From: Simon Baeumer Date: Tue, 25 Jan 2022 10:07:22 +0100 Subject: [PATCH 3/3] Add function define tests --- .../helmtest/additional_directory/inhereit_defines.test.yaml | 4 ++-- integration_test/testdata/helmtest/suite.yaml | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/integration_test/testdata/helmtest/additional_directory/inhereit_defines.test.yaml b/integration_test/testdata/helmtest/additional_directory/inhereit_defines.test.yaml index 369e2c4..0774d46 100644 --- a/integration_test/testdata/helmtest/additional_directory/inhereit_defines.test.yaml +++ b/integration_test/testdata/helmtest/additional_directory/inhereit_defines.test.yaml @@ -1,4 +1,4 @@ tests: - - name: "use defined function" + - name: "use inhereited defined function" expect: - container(.deployments.nginx, nginx) | assertThat(. != null) + container(.deployments.nginx; "nginx") | assertThat(. != null) diff --git a/integration_test/testdata/helmtest/suite.yaml b/integration_test/testdata/helmtest/suite.yaml index 2b4257b..1d4cdfb 100644 --- a/integration_test/testdata/helmtest/suite.yaml +++ b/integration_test/testdata/helmtest/suite.yaml @@ -4,3 +4,8 @@ defs: | server: visibleSchemas: - kubernetes-1.20.2 + +tests: + - name: "use defined function" + expect: + container(.deployments.nginx; "nginx") | assertThat(. != null)