From 5da1200a8b044a4342003bec5fe80220b1c46033 Mon Sep 17 00:00:00 2001 From: yxxhero <11087727+yxxhero@users.noreply.github.com> Date: Wed, 14 Dec 2022 11:38:47 +0800 Subject: [PATCH] add post render integration test (#576) Signed-off-by: yxxhero --- test/integration/charts/raw/.gitignore | 1 + test/integration/charts/raw/.helmignore | 23 ++++++++ test/integration/charts/raw/Chart.yaml | 6 +++ test/integration/charts/raw/README.md | 1 + .../charts/raw/templates/resources.yaml | 6 +++ test/integration/charts/raw/values.yaml | 48 +++++++++++++++++ test/integration/run.sh | 1 + .../integration/test-cases/postrender-diff.sh | 22 ++++++++ .../postrender-diff/input/add-cm1.bash | 13 +++++ .../postrender-diff/input/add-cm2.bash | 13 +++++ .../postrender-diff/input/helmfile.yaml | 39 ++++++++++++++ .../test-cases/postrender-diff/output/result | 52 +++++++++++++++++++ .../postrender-diff/output/result-live | 51 ++++++++++++++++++ 13 files changed, 276 insertions(+) create mode 100644 test/integration/charts/raw/.gitignore create mode 100644 test/integration/charts/raw/.helmignore create mode 100644 test/integration/charts/raw/Chart.yaml create mode 100644 test/integration/charts/raw/README.md create mode 100644 test/integration/charts/raw/templates/resources.yaml create mode 100644 test/integration/charts/raw/values.yaml create mode 100644 test/integration/test-cases/postrender-diff.sh create mode 100755 test/integration/test-cases/postrender-diff/input/add-cm1.bash create mode 100755 test/integration/test-cases/postrender-diff/input/add-cm2.bash create mode 100644 test/integration/test-cases/postrender-diff/input/helmfile.yaml create mode 100644 test/integration/test-cases/postrender-diff/output/result create mode 100644 test/integration/test-cases/postrender-diff/output/result-live diff --git a/test/integration/charts/raw/.gitignore b/test/integration/charts/raw/.gitignore new file mode 100644 index 00000000..aa1ec1ea --- /dev/null +++ b/test/integration/charts/raw/.gitignore @@ -0,0 +1 @@ +*.tgz diff --git a/test/integration/charts/raw/.helmignore b/test/integration/charts/raw/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/test/integration/charts/raw/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/test/integration/charts/raw/Chart.yaml b/test/integration/charts/raw/Chart.yaml new file mode 100644 index 00000000..5a3b7362 --- /dev/null +++ b/test/integration/charts/raw/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: raw +description: A Helm chart for Kubernetes +type: application +version: 0.0.1 +appVersion: "1.16.0" diff --git a/test/integration/charts/raw/README.md b/test/integration/charts/raw/README.md new file mode 100644 index 00000000..4e55030b --- /dev/null +++ b/test/integration/charts/raw/README.md @@ -0,0 +1 @@ +A copy of chart ../raw, but older version to test locking. diff --git a/test/integration/charts/raw/templates/resources.yaml b/test/integration/charts/raw/templates/resources.yaml new file mode 100644 index 00000000..422d2bfd --- /dev/null +++ b/test/integration/charts/raw/templates/resources.yaml @@ -0,0 +1,6 @@ +{{- range $i, $r := $.Values.templates }} +{{- if gt $i 0 }} +--- +{{- end }} +{{- (tpl $r $) }} +{{- end }} diff --git a/test/integration/charts/raw/values.yaml b/test/integration/charts/raw/values.yaml new file mode 100644 index 00000000..b761f2f6 --- /dev/null +++ b/test/integration/charts/raw/values.yaml @@ -0,0 +1,48 @@ +templates: [] + +## +## Example: Uncomment the below and run `helm template ./`: +## +# +# templates: +# - | +# apiVersion: v1 +# kind: ConfigMap +# metadata: +# name: {{ .Release.Name }}-1 +# namespace: {{ .Release.Namespace }} +# data: +# foo: {{ .Values.foo }} +# - | +# apiVersion: v1 +# kind: ConfigMap +# metadata: +# name: {{ .Release.Name }}-2 +# namespace: {{ .Release.Namespace }} +# data: +# foo: {{ .Values.foo }} +# values: +# foo: FOO +# +## +## Expected Output: +## +# +# --- +# # Source: raw/templates/resources.yaml +# apiVersion: v1 +# kind: ConfigMap +# metadata: +# name: release-name-1 +# namespace: default +# data: +# foo: +# --- +# # Source: raw/templates/resources.yaml +# apiVersion: v1 +# kind: ConfigMap +# metadata: +# name: release-name-2 +# namespace: default +# data: +# foo: diff --git a/test/integration/run.sh b/test/integration/run.sh index 85aa95db..111a1814 100755 --- a/test/integration/run.sh +++ b/test/integration/run.sh @@ -90,6 +90,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes . ${dir}/test-cases/secretssops.sh . ${dir}/test-cases/yaml-overwrite.sh . ${dir}/test-cases/chart-needs.sh +. ${dir}/test-cases/postrender-diff.sh # ALL DONE ----------------------------------------------------------------------------------------------------------- diff --git a/test/integration/test-cases/postrender-diff.sh b/test/integration/test-cases/postrender-diff.sh new file mode 100644 index 00000000..2b416d89 --- /dev/null +++ b/test/integration/test-cases/postrender-diff.sh @@ -0,0 +1,22 @@ +if [[ helm_major_version -eq 3 ]]; then + postrender_diff_case_input_dir="${cases_dir}/postrender-diff/input" + postrender_diff_case_output_dir="${cases_dir}/postrender-diff/output" + + postrender_diff_out_file=${postrender_diff_case_output_dir}/result + if [[ $EXTRA_HELMFILE_FLAGS == *--enable-live-output* ]]; then + postrender_diff_out_file=${postrender_diff_case_output_dir}/result-live + fi + + postrender_diff_tmp=$(mktemp -d) + postrender_diff_reverse=${postrender_diff_tmp}/postrender.diff.build.yaml + + test_start "postrender diff" + info "Comparing postrender diff output ${postrender_diff_reverse} with ${postrender_diff_case_output_dir}/result.yaml" + for i in $(seq 10); do + info "Comparing build/postrender-diff #$i" + ${helmfile} -f ${postrender_diff_case_input_dir}/helmfile.yaml diff --concurrency 1 &> ${postrender_diff_reverse} || fail "\"helmfile diff\" shouldn't fail" + diff -u ${postrender_diff_out_file} ${postrender_diff_reverse} || fail "\"helmfile diff\" should be consistent" + echo code=$? + done + test_pass "postrender diff" +fi \ No newline at end of file diff --git a/test/integration/test-cases/postrender-diff/input/add-cm1.bash b/test/integration/test-cases/postrender-diff/input/add-cm1.bash new file mode 100755 index 00000000..0304b012 --- /dev/null +++ b/test/integration/test-cases/postrender-diff/input/add-cm1.bash @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +cat $1 +echo "---" + +cat <