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:
-t <test file path> Execute specific test files only (all tests are executed by default).
This option can be specified multiple times.
-v Add the verbose switch to the terraform test command.
-h Display this help message.
EOF
}
......@@ -46,22 +47,42 @@ cleanup() {
trap 'cleanup' EXIT INT TERM
while getopts 'cht:v' option; do
case $option in
c) ci_run=1;;
h) usage; exit;;
t) tests+=("$OPTARG");;
v) verbose=1;;
*) all_tests=1;;
esac
ci_run=false
verbose=false
tests=()
all_tests=true # Default to true if no -t options are provided
while getopts ":cht:v" opt; do
case $opt in
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
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
shift "$((OPTIND - 1))"
test_args=("--var-file=tests/tests.tfvars")
......@@ -71,8 +92,10 @@ if [[ "${#tests[@]}" -gt 0 ]]; then
done
fi
if [[ -n $verbose ]]; then
if [ $verbose = true ]; then
test_args+=(--verbose)
echo "CI mode: $ci_run"
echo "Verbose: $verbose"
fi
# 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
> versions.tf.json
fi
if [[ -n $ci_run ]]; then
if [ "$ci_run" = true ]; then
terraform init
terraform test "${test_args[@]}"
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