From ede798ae6c64aec89d1b11fe80c942997d03d45c Mon Sep 17 00:00:00 2001 From: Alexander Todorov Date: Mon, 1 Apr 2024 12:29:16 +0300 Subject: [PATCH] Merge clean_up() into cleanup_on_exit() for filesystem.sh --- test/cases/filesystem.sh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/test/cases/filesystem.sh b/test/cases/filesystem.sh index 47ac24e81..184d0bfb3 100644 --- a/test/cases/filesystem.sh +++ b/test/cases/filesystem.sh @@ -22,9 +22,17 @@ COMPOSE_START=${TEMPDIR}/compose-start-${IMAGE_KEY}.json COMPOSE_INFO=${TEMPDIR}/compose-info-${IMAGE_KEY}.json function cleanup_on_exit() { - greenprint "== Script execution stopped or finished - Cleaning up ==" + greenprint "๐Ÿงผ Cleaning up" # kill dangling journalctl processes to prevent GitLab CI from hanging sudo pkill journalctl || echo "Nothing killed" + + # since this function can be called at any time, ensure that we don't expand unbound variables + IMAGE_FILENAME="${IMAGE_FILENAME:-}" + [ "$IMAGE_FILENAME" ] && sudo rm -f "$IMAGE_FILENAME" + + # Remove tmp dir. + sudo rm -rf "$TEMPDIR" + } trap cleanup_on_exit EXIT @@ -94,14 +102,6 @@ build_image() { fi } -# Clean up our mess. -clean_up () { - greenprint "๐Ÿงผ Cleaning up" - # Remove "remote" repo. - sudo rm -f "$IMAGE_FILENAME" - # Remove tmp dir. - sudo rm -rf "$TEMPDIR" -} check_result () { if [ ${#FAILED_MOUNTPOINTS[@]} -eq 0 ]; then greenprint "๐ŸŽ‰ $1 scenario went as expected" @@ -340,7 +340,5 @@ check_result "Failing" greenprint "๐Ÿงผ Clean up osbuild-composer again" sudo composer-cli blueprints delete custom-filesystem-fail > /dev/null -clean_up - greenprint "๐ŸŽ‰ All tests passed." exit 0