refactor: simplifies test control flow

ADP-216-wrapup
LeeW 10 months ago
parent 9877df6455
commit 51b526e90c

@ -25,7 +25,7 @@ mv .sops.yaml.tmp .sops.yaml
# define "fixture" # define "fixture"
repo_root="$(git rev-parse --show-toplevel)" 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}" >&2 echo -e "# ---\n# TEST: create sops cfg in default dir: ${repo_root}"
set -x set -x
rm "${PWD}/.sops.yaml" || : rm "${PWD}/.sops.yaml" || :
@ -39,12 +39,10 @@ if [[ 1 -eq 1 ]]; then
# enmesh: restore, since this particular one is checked in # enmesh: restore, since this particular one is checked in
git checkout "${PWD}/.sops.yaml" > /dev/null 2>&1 git checkout "${PWD}/.sops.yaml" > /dev/null 2>&1
rm "${repo_root}/.sops.yaml" 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}" >&2 echo -e "# ---\n# TEST: create sops cfg in curdir: ${PWD}"
set -x set -x
# note: fail if for any reason sops config defined at top level; this repo should not have this! # 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 # not necessary, all tracked in git
# enmesh: restore, since this particular one is checked in # enmesh: restore, since this particular one is checked in
git checkout "${PWD}/.sops.yaml" > /dev/null 2>&1 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" >&2 echo -e "# ---\n# TEST: Full Args: specify path to each, also for secrets, mix specified and positional params"
set -x set -x
../bin/update_sops.sh -k "${keys_dir}" -c "${sops_cfg_dir}" -s "${secrets_file}" "${secrets_file}" > /dev/null 2>&1 ../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 # not necessary, all tracked in git
# enmesh: restore, since this particular one is checked in # enmesh: restore, since this particular one is checked in
git checkout "${PWD}/.sops.yaml" > /dev/null 2>&1 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" >&2 echo -e "# ---\n# TEST: auto-find secrets files"
# SETUP # SETUP
_tmp_mock_secrets_dir='mock_hierarchy' _tmp_mock_secrets_dir='mock_hierarchy'
@ -108,12 +102,10 @@ if [[ 1 -eq 1 ]]; then
rm -rf "${_tmp_mock_secrets_dir}" rm -rf "${_tmp_mock_secrets_dir}"
# enmesh: restore, since this particular one is checked in # enmesh: restore, since this particular one is checked in
git checkout "${PWD}/.sops.yaml" > /dev/null 2>&1 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" >&2 echo -e "# ---\n# TEST: induce error: invalid file"
# dev note: ':' is a noop operator; could also just temporarily disable strict errors # dev note: ':' is a noop operator; could also just temporarily disable strict errors
set -x set -x
@ -123,11 +115,33 @@ if [[ 1 -eq 1 ]]; then
# not necessary, all tracked in git # not necessary, all tracked in git
# enmesh: restore, since this particular one is checked in # enmesh: restore, since this particular one is checked in
git checkout "${PWD}/.sops.yaml" > /dev/null 2>&1 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 else
>&2 echo "# INFO: skipping ...." >&2 echo "# INFO: skipping ...."
fi fi
# --- # ---
echo "TESTCASES PASSED" echo "TESTCASES PASSED"
exit 0 exit 0

Loading…
Cancel
Save