FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 19326492 authored by Roy Harrington's avatar Roy Harrington
Browse files

Merge branch '50-fix-run-test-default-behaviour' into 'master'

fix: the way run_tests.sh works with arguments

Closes #50

See merge request !75
parents f758a469 f94ec5e2
No related branches found
No related tags found
1 merge request!75fix: the way run_tests.sh works with arguments
Pipeline #595752 waiting for manual action
...@@ -16,6 +16,7 @@ Options: ...@@ -16,6 +16,7 @@ Options:
-t <test file path> Execute specific test files only (all tests are executed by default). -t <test file path> Execute specific test files only (all tests are executed by default).
This option can be specified multiple times. This option can be specified multiple times.
-v Add the verbose switch to the terraform test command. -v Add the verbose switch to the terraform test command.
-h Display this help message.
EOF EOF
} }
...@@ -46,22 +47,42 @@ cleanup() { ...@@ -46,22 +47,42 @@ cleanup() {
trap 'cleanup' EXIT INT TERM trap 'cleanup' EXIT INT TERM
while getopts 'cht:v' option; do ci_run=false
case $option in verbose=false
c) ci_run=1;; tests=()
h) usage; exit;; all_tests=true # Default to true if no -t options are provided
t) tests+=("$OPTARG");;
v) verbose=1;; while getopts ":cht:v" opt; do
*) all_tests=1;; case $opt in
esac c)
ci_run=true
;;
h)
usage
exit
;;
t)
if [ -z "$OPTARG" ] || [[ "$OPTARG" == -* ]]; then
echo "Error: Option -t requires a non-empty argument." >&2
exit 1
fi
tests+=("$OPTARG")
all_tests=false
;;
v)
verbose=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done done
shift $((OPTIND-1)) shift "$((OPTIND - 1))"
if [[ ${#tests[@]} -gt 0 && -n $all_tests ]]; then
echo -e "Error: Cannot specify both -a and -t together.\n"
usage
exit 1
fi
test_args=("--var-file=tests/tests.tfvars") test_args=("--var-file=tests/tests.tfvars")
...@@ -71,8 +92,10 @@ if [[ "${#tests[@]}" -gt 0 ]]; then ...@@ -71,8 +92,10 @@ if [[ "${#tests[@]}" -gt 0 ]]; then
done done
fi fi
if [[ -n $verbose ]]; then if [ $verbose = true ]; then
test_args+=(--verbose) test_args+=(--verbose)
echo "CI mode: $ci_run"
echo "Verbose: $verbose"
fi fi
# Comment out the prevent_destroy lifecycle argument otherwise the tests will fail as they cannot tear down the # Comment out the prevent_destroy lifecycle argument otherwise the tests will fail as they cannot tear down the
...@@ -87,7 +110,7 @@ if [[ -n $GOOGLE_PROVIDER_VERSION_CONSTRAINT ]]; then ...@@ -87,7 +110,7 @@ if [[ -n $GOOGLE_PROVIDER_VERSION_CONSTRAINT ]]; then
> versions.tf.json > versions.tf.json
fi fi
if [[ -n $ci_run ]]; then if [ "$ci_run" = true ]; then
terraform init terraform init
terraform test "${test_args[@]}" terraform test "${test_args[@]}"
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment