Skip to content

Commit 806c7ee

Browse files
committed
fix(shell): add error handling and proper quoting to run_tests.sh
- Add set -euo pipefail for strict error handling - Quote all variable references ($KUBECONFIG, $KUBECONFIG_EDGE, $WORKSPACE) - Use ${VAR:-} syntax for unset variable checks with set -u - Use mktemp -d instead of /tmp for secure temporary directory - Tests will now fail fast on any error instead of continuing
1 parent 41bf166 commit 806c7ee

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

tests/interop/run_tests.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
11
#!/usr/bin/bash
2+
set -euo pipefail
23

34
export EXTERNAL_TEST="true"
45
export PATTERN_NAME="MultiCloudGitops"
56
export PATTERN_SHORTNAME="mcgitops"
67

7-
if [ -z "${KUBECONFIG}" ]; then
8+
if [ -z "${KUBECONFIG:-}" ]; then
89
echo "No kubeconfig file set for hub cluster"
910
exit 1
1011
fi
1112

12-
if [ -z "${KUBECONFIG_EDGE}" ]; then
13+
if [ -z "${KUBECONFIG_EDGE:-}" ]; then
1314
echo "No kubeconfig file set for edge cluster"
1415
exit 1
1516
fi
1617

17-
if [ -z "${INFRA_PROVIDER}" ]; then
18+
if [ -z "${INFRA_PROVIDER:-}" ]; then
1819
echo "INFRA_PROVIDER is not defined"
1920
exit 1
2021
fi
2122

22-
if [ -z "${WORKSPACE}" ]; then
23-
export WORKSPACE=/tmp
23+
if [ -z "${WORKSPACE:-}" ]; then
24+
WORKSPACE=$(mktemp -d)
25+
export WORKSPACE
26+
echo "WORKSPACE not set, using temporary directory: ${WORKSPACE}"
2427
fi
2528

26-
pytest -lv --disable-warnings test_subscription_status_hub.py --kubeconfig $KUBECONFIG --junit-xml $WORKSPACE/test_subscription_status_hub.xml
29+
pytest -lv --disable-warnings test_subscription_status_hub.py --kubeconfig "$KUBECONFIG" --junit-xml "$WORKSPACE/test_subscription_status_hub.xml"
2730

28-
pytest -lv --disable-warnings test_subscription_status_edge.py --kubeconfig $KUBECONFIG_EDGE --junit-xml $WORKSPACE/test_subscription_status_edge.xml
31+
pytest -lv --disable-warnings test_subscription_status_edge.py --kubeconfig "$KUBECONFIG_EDGE" --junit-xml "$WORKSPACE/test_subscription_status_edge.xml"
2932

30-
pytest -lv --disable-warnings test_validate_hub_site_components.py --kubeconfig $KUBECONFIG --junit-xml $WORKSPACE/test_validate_hub_site_components.xml
33+
pytest -lv --disable-warnings test_validate_hub_site_components.py --kubeconfig "$KUBECONFIG" --junit-xml "$WORKSPACE/test_validate_hub_site_components.xml"
3134

32-
pytest -lv --disable-warnings test_validate_edge_site_components.py --kubeconfig $KUBECONFIG_EDGE --junit-xml $WORKSPACE/test_validate_edge_site_components.xml
35+
pytest -lv --disable-warnings test_validate_edge_site_components.py --kubeconfig "$KUBECONFIG_EDGE" --junit-xml "$WORKSPACE/test_validate_edge_site_components.xml"
3336

34-
pytest -lv --disable-warnings test_modify_web_content.py --kubeconfig $KUBECONFIG --junit-xml $WORKSPACE/test_modify_web_content.xml
37+
pytest -lv --disable-warnings test_modify_web_content.py --kubeconfig "$KUBECONFIG" --junit-xml "$WORKSPACE/test_modify_web_content.xml"
3538

3639
python3 create_ci_badge.py

0 commit comments

Comments
 (0)