Skip to content

Commit

Permalink
Implement a bit of sanity
Browse files Browse the repository at this point in the history
  • Loading branch information
dflook committed Jun 1, 2024
1 parent 83975e2 commit f9d6d91
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
exit 1
fi
if [[ "${{ steps.failing.outputs.failure-reason }}" != "tests-failed" ]]; then
if [[ "${{ steps.failing.outputs.failure-reason }}" != "no-tests" ]]; then
echo "::error:: failure-reason not set correctly"
exit 1
fi
Expand All @@ -109,7 +109,7 @@ jobs:
continue-on-error: true
with:
path: tests/workflows/test-test/local
filter: |
test_filter: |
tests/this-test-does-not-exist.tftest.hcl
tests/nor-does-this-one.tftest.hcl
Expand All @@ -120,7 +120,7 @@ jobs:
exit 1
fi
if [[ "${{ steps.failing.outputs.failure-reason }}" != "tests-failed" ]]; then
if [[ "${{ steps.failing.outputs.failure-reason }}" != "no-tests" ]]; then
echo "::error:: failure-reason not set correctly"
exit 1
fi
Expand Down
38 changes: 32 additions & 6 deletions image/entrypoints/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ debug
setup
init-test

exec 3>&1

function set-test-args() {
TEST_ARGS=""

Expand All @@ -26,13 +28,37 @@ function set-test-args() {
fi
}

set-test-args
function test() {

debug_log $TOOL_COMMAND_NAME test -no-color $TEST_ARGS '$PLAN_ARGS' # don't expand PLAN_ARGS

set +e
# shellcheck disable=SC2086
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME test -no-color $TEST_ARGS $PLAN_ARGS) \
2>"$STEP_TMP_DIR/terraform_test.stderr" \
| tee /dev/fd/3 \
>"$STEP_TMP_DIR/terraform_test.stdout"

# shellcheck disable=SC2034
TEST_EXIT=${PIPESTATUS[0]}
set -e

cat "$STEP_TMP_DIR/terraform_test.stderr"

if [[ $TEST_EXIT -eq 0 ]]; then
# Workaround a bit of stupidity in the terraform test command
if grep -q "Success! 0 passed, 0 failed." "$STEP_TMP_DIR/terraform_test.stdout"; then
set_output failure-reason no-tests
exit 1
fi
else
set_output failure-reason tests-failed
exit 1
fi
}

set-test-args
PLAN_ARGS=""
set-variable-args

debug_log $TOOL_COMMAND_NAME test -no-color $TEST_ARGS '$PLAN_ARGS' # don't expand PLAN_ARGS
if ! (cd "$INPUT_PATH" && $TOOL_COMMAND_NAME test -no-color $TEST_ARGS $PLAN_ARGS); then
set_output failure-reason tests-failed
exit 1
fi
test

0 comments on commit f9d6d91

Please sign in to comment.