From aff320d80947228f402171f53b3da8306c44a33e Mon Sep 17 00:00:00 2001 From: Lee Watson Date: Tue, 11 Mar 2025 10:36:26 +0000 Subject: [PATCH] ADP-216 simplifies test control flow --- verify/test.sh | 52 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/verify/test.sh b/verify/test.sh index 4a023ba..7d4bf1a 100755 --- a/verify/test.sh +++ b/verify/test.sh @@ -25,7 +25,7 @@ mv .sops.yaml.tmp .sops.yaml # define "fixture" repo_root="$(git rev-parse --show-toplevel)" # --- -if [[ 1 -eq 1 ]]; then +function fn_test_create_sops_cfg_default(){ >&2 echo -e "# ---\n# TEST: create sops cfg in default dir: ${repo_root}" set -x rm "${PWD}/.sops.yaml" || : @@ -39,12 +39,10 @@ if [[ 1 -eq 1 ]]; then # enmesh: restore, since this particular one is checked in git checkout "${PWD}/.sops.yaml" > /dev/null 2>&1 rm "${repo_root}/.sops.yaml" -else - >&2 echo "# INFO: skipping ...." -fi +} # --- -if [[ 1 -eq 1 ]]; then +function fn_test_create_sops_cfg_dir_cwd(){ >&2 echo -e "# ---\n# TEST: create sops cfg in curdir: ${PWD}" set -x # note: fail if for any reason sops config defined at top level; this repo should not have this! @@ -59,12 +57,10 @@ if [[ 1 -eq 1 ]]; then # not necessary, all tracked in git # enmesh: restore, since this particular one is checked in git checkout "${PWD}/.sops.yaml" > /dev/null 2>&1 -else - >&2 echo "# INFO: skipping ...." -fi +} # --- -if [[ 1 -eq 1 ]]; then +function fn_test_create_sops_cfg_opts_complex_1(){ >&2 echo -e "# ---\n# TEST: Full Args: specify path to each, also for secrets, mix specified and positional params" set -x ../bin/update_sops.sh -k "${keys_dir}" -c "${sops_cfg_dir}" -s "${secrets_file}" "${secrets_file}" > /dev/null 2>&1 @@ -73,12 +69,10 @@ if [[ 1 -eq 1 ]]; then # not necessary, all tracked in git # enmesh: restore, since this particular one is checked in git checkout "${PWD}/.sops.yaml" > /dev/null 2>&1 -else - >&2 echo "# INFO: skipping ...." -fi +} # --- -if [[ 1 -eq 1 ]]; then +function fn_test_auto_find_secrets_files(){ >&2 echo -e "# ---\n# TEST: auto-find secrets files" # SETUP _tmp_mock_secrets_dir='mock_hierarchy' @@ -108,12 +102,10 @@ if [[ 1 -eq 1 ]]; then rm -rf "${_tmp_mock_secrets_dir}" # enmesh: restore, since this particular one is checked in git checkout "${PWD}/.sops.yaml" > /dev/null 2>&1 -else - >&2 echo "# INFO: skipping ...." -fi +} # --- -if [[ 1 -eq 1 ]]; then +function fn_test_expect_error_invalid_file(){ >&2 echo -e "# ---\n# TEST: induce error: invalid file" # dev note: ':' is a noop operator; could also just temporarily disable strict errors set -x @@ -123,11 +115,33 @@ if [[ 1 -eq 1 ]]; then # not necessary, all tracked in git # enmesh: restore, since this particular one is checked in git checkout "${PWD}/.sops.yaml" > /dev/null 2>&1 +} + +if [[ 1 -eq 1 ]]; then + fn_test_create_sops_cfg_default +else + >&2 echo "# INFO: skipping ...." +fi +if [[ 1 -eq 1 ]]; then + fn_test_create_sops_cfg_dir_cwd +else + >&2 echo "# INFO: skipping ...." +fi +if [[ 1 -eq 1 ]]; then + fn_test_create_sops_cfg_opts_complex_1 +else + >&2 echo "# INFO: skipping ...." +fi +if [[ 1 -eq 1 ]]; then + fn_test_auto_find_secrets_files +else + >&2 echo "# INFO: skipping ...." +fi +if [[ 1 -eq 1 ]]; then + fn_test_expect_error_invalid_file else >&2 echo "# INFO: skipping ...." fi - - # --- echo "TESTCASES PASSED" exit 0