Skip to content

Commit

Permalink
Merge pull request #420 from ABWassim/fix/set-value-array
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke authored Nov 18, 2023
2 parents 5f87e40 + 988ce19 commit dcea153
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 2 deletions.
26 changes: 24 additions & 2 deletions scripts/commands/helm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ helm_wrapper() {
IFS=","
_literal=""

set_list=false

for literal in ${literals}; do
unset IFS

opt_prefix=""

case "${literal}" in
*\\)
_literal="${literal}"
Expand All @@ -84,8 +88,26 @@ helm_wrapper() {
_literal=""
fi

opt_prefix="${literal%%=*}="
literal="${literal#*=}"
if [ "${set_list}" = "false" ]; then
opt_prefix="${literal%%=*}"

if [ "$opt_prefix" != "" ]; then
opt_prefix="${opt_prefix}="
fi

literal="${literal#*=}"
fi

case "${literal}" in
\\\{*) ;;
*\\\}) ;;
\{*)
set_list=true
;;
*\})
set_list=false
;;
esac

# Force secret backend
if [ "${literal#*!}" != "${literal}" ]; then
Expand Down
Empty file added tests/http.yaml
Empty file.
88 changes: 88 additions & 0 deletions tests/unit/template.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2136,3 +2136,91 @@ key2: value" 2>&1
assert_success
assert_file_not_exists "${VALUES_PATH}.dec"
}

@test "template: helm template w/ chart + --set imagePullSecrets={fr,en,de,zh,ko}" {
if on_windows || on_wsl; then
skip
fi

create_chart "${TEST_TEMP_DIR}"

run "${HELM_BIN}" secrets template --set "imagePullSecrets={fr,en,de,zh,ko}" "${TEST_TEMP_DIR}/chart" 2>&1

assert_output --partial "- fr"
assert_output --partial "- en"
assert_output --partial "- de"
assert_output --partial "- zh"
assert_output --partial "- ko"
assert_success
}

@test "template: helm template w/ chart + --set imagePullSecrets={fr,en,de,zh,ko} with quoted values" {
if on_windows || on_wsl; then
skip
fi

create_chart "${TEST_TEMP_DIR}"

run "${HELM_BIN}" secrets template --set 'imagePullSecrets={"fr","en","de","zh","ko"}' "${TEST_TEMP_DIR}/chart" 2>&1

assert_output --partial "- '\"fr\"'"
assert_output --partial "- '\"en\"'"
assert_output --partial "- '\"de\"'"
assert_output --partial "- '\"zh\"'"
assert_output --partial "- '\"ko\"'"
assert_success
}

@test "template: helm template w/ chart + --set imagePullSecrets={fr,en,de,zh,ko} with escaped comma" {
if on_windows || on_wsl; then
skip
fi

create_chart "${TEST_TEMP_DIR}"

run "${HELM_BIN}" secrets template --set 'imagePullSecrets={"fr","e\,n","de","zh","ko"}' "${TEST_TEMP_DIR}/chart" 2>&1

assert_output --partial "- '\"fr\"'"
assert_output --partial "- '\"e,n\"'"
assert_output --partial "- '\"de\"'"
assert_output --partial "- '\"zh\"'"
assert_output --partial "- '\"ko\"'"
assert_success
}

@test "template: helm template w/ chart + --set imagePullSecrets={fr,en,de,zh,ko} with escaped bracket" {
if on_windows || on_wsl; then
skip
fi

create_chart "${TEST_TEMP_DIR}"

run "${HELM_BIN}" secrets template --set 'imagePullSecrets={fr,de,\}3\,2,ko,zh}' "${TEST_TEMP_DIR}/chart" 2>&1

assert_output --partial "- fr"
assert_output --partial "- de"
assert_output --partial "- '}3,2'"
assert_output --partial "- zh"
assert_output --partial "- ko"
assert_success
}

@test "template: helm template w/ chart + --set imagePullSecrets={fr,en,de,zh,ko} with multiple escaped values" {
if on_windows || on_wsl; then
skip
fi

create_chart "${TEST_TEMP_DIR}"

run "${HELM_BIN}" secrets template --set 'imagePullSecrets={fr,d\,e,en,ko,zh},service.port=87,podAnnotations.second=Hello{Wo\,a' "${TEST_TEMP_DIR}/chart" 2>&1

assert_output --partial "- fr"
assert_output --partial "- d,e"
assert_output --partial "- en"
assert_output --partial "- zh"
assert_output --partial "- ko"

assert_output --partial "port: 87"
assert_output --partial "second: Hello{Wo,a"
assert_success
}

0 comments on commit dcea153

Please sign in to comment.