Add jsonPatches regression coverage for chartify lookup rendering (#2586)

* test: cover jsonPatches lookup regression

Agent-Logs-Url: https://github.com/helmfile/helmfile/sessions/72b7ba14-50b8-4407-ba37-6da202609603

Co-authored-by: zhaque44 <20215376+zhaque44@users.noreply.github.com>

* test: simplify json patch fixture

Agent-Logs-Url: https://github.com/helmfile/helmfile/sessions/72b7ba14-50b8-4407-ba37-6da202609603

Co-authored-by: zhaque44 <20215376+zhaque44@users.noreply.github.com>

* test: target existing json patch path

Agent-Logs-Url: https://github.com/helmfile/helmfile/sessions/72b7ba14-50b8-4407-ba37-6da202609603

Co-authored-by: zhaque44 <20215376+zhaque44@users.noreply.github.com>

* test: validate diff exit codes in issue-2271

Agent-Logs-Url: https://github.com/helmfile/helmfile/sessions/5615c543-f96b-44ed-be25-ca1559ee6ab0

Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: zhaque44 <20215376+zhaque44@users.noreply.github.com>
Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com>
This commit is contained in:
Copilot 2026-05-20 17:02:45 +08:00 committed by GitHub
parent 81ab674017
commit 2f2e8617ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 52 additions and 18 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Test for issue #2271: lookup function should work with strategicMergePatches
# Test for issue #2271: lookup function should work with strategicMergePatches and jsonPatches
# Without this fix, helm template runs client-side and lookup() returns empty values
issue_2271_input_dir="${cases_dir}/issue-2271/input"
@ -8,7 +8,7 @@ issue_2271_tmp_dir=$(mktemp -d)
cd "${issue_2271_input_dir}"
test_start "issue-2271: lookup function with strategicMergePatches"
test_start "issue-2271: lookup function with strategicMergePatches and jsonPatches"
# Test 1: Install chart without kustomize patches
info "Installing chart without kustomize patches"
@ -36,26 +36,44 @@ fi
info "ConfigMap value updated to: $current_value"
assert_lookup_preserved() {
local label="$1"
local helmfile_path="$2"
local output_path="$3"
local code
info "Testing diff with ${label} - lookup should preserve value"
${helmfile} -f "${helmfile_path}" diff > "${output_path}" 2>&1
code=$?
if [ $code -ne 0 ] && [ $code -ne 2 ]; then
cat "${output_path}"
rm -rf "${issue_2271_tmp_dir}"
fail "Unexpected error during diff with ${label}"
fi
# Check if the diff contains the preserved value (not "initial-value")
if grep -q "preserved-value.*test-preserved-value" "${output_path}"; then
info "SUCCESS: lookup function preserved the value with ${label}"
elif grep -q "preserved-value.*initial-value" "${output_path}"; then
cat "${output_path}"
rm -rf "${issue_2271_tmp_dir}"
fail "Issue #2271 regression: lookup function returned empty value with ${label}"
else
# No diff for ConfigMap means value is perfectly preserved
info "SUCCESS: No ConfigMap changes detected for ${label} (value perfectly preserved)"
fi
}
# Test 3: Diff with strategicMergePatches should preserve the lookup value
info "Testing diff with strategicMergePatches - lookup should preserve value"
assert_lookup_preserved "strategicMergePatches" "helmfile.yaml" "${issue_2271_tmp_dir}/test-2271-strategic-diff.txt"
${helmfile} -f helmfile.yaml diff > "${issue_2271_tmp_dir}/test-2271-diff.txt" 2>&1
code=$?
# Check if the diff contains the preserved value (not "initial-value")
if grep -q "preserved-value.*test-preserved-value" "${issue_2271_tmp_dir}/test-2271-diff.txt"; then
info "SUCCESS: lookup function preserved the value with kustomize patches"
elif grep -q "preserved-value.*initial-value" "${issue_2271_tmp_dir}/test-2271-diff.txt"; then
cat "${issue_2271_tmp_dir}/test-2271-diff.txt"
rm -rf "${issue_2271_tmp_dir}"
fail "Issue #2271 regression: lookup function returned empty value with kustomize"
else
# No diff for ConfigMap means value is perfectly preserved
info "SUCCESS: No ConfigMap changes detected (value perfectly preserved)"
fi
# Test 4: Diff with jsonPatches should preserve the lookup value
assert_lookup_preserved "jsonPatches" "helmfile-jsonpatch.yaml" "${issue_2271_tmp_dir}/test-2271-json-diff.txt"
# Cleanup
${helm} uninstall test-release-2271 --namespace default 2>/dev/null || true
rm -rf "${issue_2271_tmp_dir}"
test_pass "issue-2271: lookup function with strategicMergePatches"
test_pass "issue-2271: lookup function with strategicMergePatches and jsonPatches"

View File

@ -0,0 +1,16 @@
releases:
- name: test-release-2271
namespace: default
chart: ./test-chart
installed: true
jsonPatches:
- target:
group: apps
version: v1
kind: Deployment
name: test-release-2271-app
namespace: default
patch:
- op: add
path: /spec/template/metadata/labels/hello
value: world