Files
helmfile/test/integration/test-cases/issue-2271.sh
T
yxxhero bbf925f154 test: add integration test for issue #1880 transformers with file:// deps (#2673)
* test: add integration test for issue #1880 transformers with file:// deps

Add an integration test reproducing the exact scenario from issue #1880:
a local chart with a relative file:// dependency (file://../library) used
together with kustomize transformers.

Before the fix (rewriteChartDependencies in PR #2334), chartify copied
the chart to a temp directory, breaking the relative file:// path and
causing helm dependency up to fail with:
  Error: directory /tmp/chartify.../monitoring/library not found

Also fix test artifact leak in issue923_test.go where OCI chart downloads
wrote to CWD because OutputDirTemplate lacked {{ .OutputDir }}.

Closes #1880

Signed-off-by: yxxhero <aiopsclub@163.com>

* fix(test): guard exit-code captures against set -e in integration tests

Under set -e (enabled in run.sh), a failing command exits the shell
before 'var=$?' can execute, defeating diagnostic cat+fail blocks and
breaking helm diff tests that expect exit code 2.

Replaced 'cmd; var=$?' with 'var=0; cmd || var=$?' across 12 test
files (29 sites), matching the pattern already used in oci-parallel-pull.sh.

Signed-off-by: yxxhero <aiopsclub@163.com>

---------

Signed-off-by: yxxhero <aiopsclub@163.com>
2026-06-29 08:49:51 +08:00

80 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# 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"
issue_2271_tmp_dir=$(mktemp -d)
cd "${issue_2271_input_dir}"
test_start "issue-2271: lookup function with strategicMergePatches and jsonPatches"
# Test 1: Install chart without kustomize patches
info "Installing chart without kustomize patches"
code=0
${helmfile} -f helmfile-no-kustomize.yaml apply --suppress-diff > "${issue_2271_tmp_dir}/test-2271-install.txt" 2>&1 || code=$?
if [ $code -ne 0 ]; then
cat "${issue_2271_tmp_dir}/test-2271-install.txt"
rm -rf "${issue_2271_tmp_dir}"
fail "Failed to install chart"
fi
info "Chart installed successfully"
# Test 2: Modify ConfigMap value manually to simulate an upgrade scenario
info "Modifying ConfigMap value to test lookup preservation"
${kubectl} patch configmap test-release-2271-config --type merge -p '{"data":{"preserved-value":"test-preserved-value"}}' > /dev/null 2>&1
# Verify the value was changed
current_value=$(${kubectl} get configmap test-release-2271-config -o jsonpath='{.data.preserved-value}')
if [ "$current_value" != "test-preserved-value" ]; then
rm -rf "${issue_2271_tmp_dir}"
fail "Failed to update ConfigMap value. Got: $current_value"
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"
code=0
${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
assert_lookup_preserved "strategicMergePatches" "helmfile.yaml" "${issue_2271_tmp_dir}/test-2271-strategic-diff.txt"
# 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 and jsonPatches"