From fbaa7a4f8f5d358eabceb73546cfe86bfab28e7d Mon Sep 17 00:00:00 2001 From: yxxhero Date: Sun, 15 Mar 2026 14:31:56 +0800 Subject: [PATCH] test: add integration test for include-needs vs include-transitive-needs Signed-off-by: yxxhero --- test/integration/run.sh | 1 + .../test-cases/include-needs-transitive.sh | 74 +++++++++++++++++++ .../input/helmfile.yaml | 56 ++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 test/integration/test-cases/include-needs-transitive.sh create mode 100644 test/integration/test-cases/include-needs-transitive/input/helmfile.yaml diff --git a/test/integration/run.sh b/test/integration/run.sh index 80099707..e88df567 100755 --- a/test/integration/run.sh +++ b/test/integration/run.sh @@ -137,6 +137,7 @@ ${kubectl} create namespace ${test_ns} || fail "Could not create namespace ${tes . ${dir}/test-cases/issue-2424-sequential-values-paths.sh . ${dir}/test-cases/issue-2431.sh . ${dir}/test-cases/kubedog-tracking.sh +. ${dir}/test-cases/include-needs-transitive.sh # ALL DONE ----------------------------------------------------------------------------------------------------------- diff --git a/test/integration/test-cases/include-needs-transitive.sh b/test/integration/test-cases/include-needs-transitive.sh new file mode 100644 index 00000000..318d74ae --- /dev/null +++ b/test/integration/test-cases/include-needs-transitive.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +# Test case for --include-needs vs --include-transitive-needs +# This test verifies that: +# 1. --include-needs includes only direct dependencies +# 2. --include-transitive-needs includes all transitive dependencies +# 3. Log message shows correct count of releases matching selector (not including needs) + +include_needs_case_input_dir="${cases_dir}/include-needs-transitive/input" +include_needs_tmp=$(mktemp -d) + +test_start "include-needs vs include-transitive-needs" + +# Test 1: --include-needs should include only direct dependencies +info "Testing --include-needs includes only direct dependencies" +${helmfile} -f ${include_needs_case_input_dir}/helmfile.yaml -l name=serviceA template --include-needs > ${include_needs_tmp}/include-needs.log 2>&1 || fail "helmfile template --include-needs should not fail" + +# Verify that serviceA, serviceB are included in the output (serviceB is direct need of serviceA) +# serviceC should NOT be included (it's transitive, not direct) +include_needs_output=$(cat ${include_needs_tmp}/include-needs.log) + +if echo "${include_needs_output}" | grep -q "name: serviceA" && \ + echo "${include_needs_output}" | grep -q "name: serviceB" && \ + ! echo "${include_needs_output}" | grep -q "name: serviceC"; then + info "--include-needs correctly includes only direct dependencies (serviceA, serviceB)" +else + cat ${include_needs_tmp}/include-needs.log + fail "--include-needs should include only serviceA and serviceB (direct need), not serviceC (transitive)" +fi + +# Verify log shows "1 release(s) matching name=serviceA" (not 2 or 3) +if echo "${include_needs_output}" | grep -q "1 release(s) matching name=serviceA"; then + info "Log correctly shows 1 release matching selector" +else + cat ${include_needs_tmp}/include-needs.log + fail "Log should show '1 release(s) matching name=serviceA', not including needs count" +fi + +# Test 2: --include-transitive-needs should include all transitive dependencies +info "Testing --include-transitive-needs includes all transitive dependencies" +${helmfile} -f ${include_needs_case_input_dir}/helmfile.yaml -l name=serviceA template --include-transitive-needs > ${include_needs_tmp}/include-transitive-needs.log 2>&1 || fail "helmfile template --include-transitive-needs should not fail" + +# Verify that serviceA, serviceB, serviceC are all included +transitive_output=$(cat ${include_needs_tmp}/include-transitive-needs.log) + +if echo "${transitive_output}" | grep -q "name: serviceA" && \ + echo "${transitive_output}" | grep -q "name: serviceB" && \ + echo "${transitive_output}" | grep -q "name: serviceC"; then + info "--include-transitive-needs correctly includes all transitive dependencies (serviceA, serviceB, serviceC)" +else + cat ${include_needs_tmp}/include-transitive-needs.log + fail "--include-transitive-needs should include serviceA, serviceB, and serviceC (transitive)" +fi + +# Verify log still shows "1 release(s) matching name=serviceA" (selector match, not total) +if echo "${transitive_output}" | grep -q "1 release(s) matching name=serviceA"; then + info "Log correctly shows 1 release matching selector (not including transitive needs)" +else + cat ${include_needs_tmp}/include-transitive-needs.log + fail "Log should show '1 release(s) matching name=serviceA', not including needs count" +fi + +# Test 3: Verify serviceD is never included (not in dependency chain) +if ! echo "${include_needs_output}" | grep -q "name: serviceD" && \ + ! echo "${transitive_output}" | grep -q "name: serviceD"; then + info "serviceD correctly not included (not in dependency chain)" +else + fail "serviceD should never be included as it's not in the dependency chain" +fi + +# Cleanup +rm -rf ${include_needs_tmp} + +test_pass "include-needs vs include-transitive-needs" diff --git a/test/integration/test-cases/include-needs-transitive/input/helmfile.yaml b/test/integration/test-cases/include-needs-transitive/input/helmfile.yaml new file mode 100644 index 00000000..6d6c97b7 --- /dev/null +++ b/test/integration/test-cases/include-needs-transitive/input/helmfile.yaml @@ -0,0 +1,56 @@ +releases: + - name: serviceA + chart: ../../../charts/raw + values: + - templates: + - | + apiVersion: v1 + kind: ConfigMap + metadata: + name: {{ .Release.Name }} + namespace: {{ .Release.Namespace }} + data: + name: {{ .Release.Name }} + needs: + - serviceB + + - name: serviceB + chart: ../../../charts/raw + values: + - templates: + - | + apiVersion: v1 + kind: ConfigMap + metadata: + name: {{ .Release.Name }} + namespace: {{ .Release.Namespace }} + data: + name: {{ .Release.Name }} + needs: + - serviceC + + - name: serviceC + chart: ../../../charts/raw + values: + - templates: + - | + apiVersion: v1 + kind: ConfigMap + metadata: + name: {{ .Release.Name }} + namespace: {{ .Release.Namespace }} + data: + name: {{ .Release.Name }} + + - name: serviceD + chart: ../../../charts/raw + values: + - templates: + - | + apiVersion: v1 + kind: ConfigMap + metadata: + name: {{ .Release.Name }} + namespace: {{ .Release.Namespace }} + data: + name: {{ .Release.Name }}