|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Purpose: Run Terraform provider acceptance tests with automatic selective re-runs |
| 3 | +# of only the failing tests to mitigate flakiness (e.g. transient upstream/network issues). |
| 4 | +# |
| 5 | +# Environment variables (override as needed): |
| 6 | +# PARALLEL Go test -parallel value (default 6) |
| 7 | +# TIMEOUT Per test package timeout (default 30m) |
| 8 | +# RERUN_MAX_TIMES How many times to re-run a failing test (default 2) |
| 9 | +# RERUN_FAILS Max number of distinct failing tests eligible for rerun (default 50) |
| 10 | +# EXTRA_ARGS Extra args to pass through to `go test` after the rerun flags |
| 11 | +# TF_ACC Forced to 1 if unset (enables acceptance tests) |
| 12 | +# |
| 13 | +# Output: |
| 14 | +# - test-report.xml (JUnit format) for CI annotation |
| 15 | +# - streaming stdout with concise first-run + rerun summaries |
| 16 | +# - exit code 0 only if all tests eventually pass within rerun budget |
| 17 | +# |
| 18 | +# Requires: gotestsum (installed automatically if missing) |
| 19 | +set -euo pipefail |
| 20 | + |
| 21 | +PARALLEL=${PARALLEL:-6} |
| 22 | +TIMEOUT=${TIMEOUT:-30m} |
| 23 | +RERUN_MAX_TIMES=${RERUN_MAX_TIMES:-2} |
| 24 | +RERUN_FAILS=${RERUN_FAILS:-50} |
| 25 | +EXTRA_ARGS=${EXTRA_ARGS:-} |
| 26 | + |
| 27 | +export TF_ACC=${TF_ACC:-1} |
| 28 | + |
| 29 | +if ! command -v gotestsum >/dev/null 2>&1; then |
| 30 | + echo "[INFO] Installing gotestsum (not found in PATH)" >&2 |
| 31 | + # Pin a version for reproducibility; update periodically. |
| 32 | + go install gotest.tools/gotestsum@v1.12.0 |
| 33 | +fi |
| 34 | + |
| 35 | +echo "[INFO] Running acceptance tests with selective reruns" |
| 36 | +echo " parallel=${PARALLEL} timeout=${TIMEOUT} rerun_max_times=${RERUN_MAX_TIMES} rerun_fails=${RERUN_FAILS}" \ |
| 37 | + " extra_args='${EXTRA_ARGS}'" |
| 38 | + |
| 39 | +# We disable test caching (-count=1) to ensure fresh runs against live APIs. |
| 40 | +set +e |
| 41 | +gotestsum --format=short-verbose \ |
| 42 | + --junitfile test-report.xml \ |
| 43 | + --rerun-fails="${RERUN_FAILS}" \ |
| 44 | + --rerun-fails-max-times="${RERUN_MAX_TIMES}" \ |
| 45 | + --packages="./..." \ |
| 46 | + -- -count=1 -parallel="${PARALLEL}" -timeout="${TIMEOUT}" ${EXTRA_ARGS} |
| 47 | +status=$? |
| 48 | +set -e |
| 49 | + |
| 50 | +if [ $status -ne 0 ]; then |
| 51 | + echo "[ERROR] Acceptance tests failed after selective reruns." >&2 |
| 52 | +else |
| 53 | + echo "[INFO] All acceptance tests passed (including reruns)." >&2 |
| 54 | +fi |
| 55 | + |
| 56 | +exit $status |
0 commit comments