From 90786a6d6c1b08a70e49bd62f795eff8ac7581d1 Mon Sep 17 00:00:00 2001 From: kai Date: Tue, 28 Jul 2026 11:30:32 +0100 Subject: [PATCH] Delete the test snapshot in teardown so failures don't orphan it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The DELETE was the last statement of each test body, so it only ran when every assertion passed. Any failure after the upload left the snapshot in turbot-ops/clitesting permanently — and the tests upload on every CI run, so those accumulate. Capture the delete URL immediately after the upload and move the DELETE into a bats teardown, which runs whether the test passes or fails. The guard on an empty URL covers a skipped test and an upload that never returned one. --- tests/acceptance/test_files/snapshot.bats | 52 ++++++++++++----------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/tests/acceptance/test_files/snapshot.bats b/tests/acceptance/test_files/snapshot.bats index 9ef20c182..59efdb0cd 100644 --- a/tests/acceptance/test_files/snapshot.bats +++ b/tests/acceptance/test_files/snapshot.bats @@ -9,6 +9,18 @@ function setup() { if [[ -z "${SPIPETOOLS_TOKEN}" ]]; then skip fi + req_url="" +} + +# Runs after every test, including failing ones. Deleting the snapshot inline at +# the end of a test only happened when every assertion passed, so any failure +# after the upload left the snapshot behind in the workspace for good. +function teardown() { + rm -f output.* + + if [[ -n "${req_url}" ]]; then + curl -s -X DELETE "$req_url" -H "Authorization: Bearer $SPIPETOOLS_TOKEN" || true + fi } @test "snapshot mode - query output csv" { @@ -20,6 +32,11 @@ function setup() { url=$(grep -o 'http[^"]*' output.csv) echo $url + # create the snapshot DELETE Request URL, so teardown can remove it whatever + # the assertions below do + req_url=$($FILE_PATH/url_parse.sh $url) + echo $req_url + # checking for OS type, since sed command is different for linux and OSX # removing the 15th line, since it contains snapshot upload link, which will be different in each run if [[ "$OSTYPE" == "darwin"* ]]; then @@ -29,15 +46,7 @@ function setup() { fi cat output.csv - # create the snapshot DELETE Request URL - req_url=$($FILE_PATH/url_parse.sh $url) - echo $req_url - assert_equal "$(cat output.csv)" "$(cat $TEST_DATA_DIR/expected_static_query_csv_snapshot_mode.csv)" - rm -f output.* - - # delete the snapshot from cloud workspace to avoid exceeding quota - curl -X DELETE "$req_url" -H "Authorization: Bearer $SPIPETOOLS_TOKEN" } @test "snapshot mode - query output json" { @@ -50,6 +59,11 @@ function setup() { url=$(grep -o 'http[^"]*' output.json) echo $url + # create the snapshot DELETE Request URL, so teardown can remove it whatever + # the assertions below do + req_url=$($FILE_PATH/url_parse.sh $url) + echo $req_url + # checking for OS type, since sed command is different for linux and OSX # removing the 64th line, since it contains snapshot upload link, which will be different in each run if [[ "$OSTYPE" == "darwin"* ]]; then @@ -59,15 +73,7 @@ function setup() { fi cat output.json - # create the snapshot DELETE Request URL - req_url=$($FILE_PATH/url_parse.sh $url) - echo $req_url - assert_equal "$(cat output.json)" "$(cat $TEST_DATA_DIR/expected_static_query_json_snapshot_mode.json)" - rm -f output.* - - # delete the snapshot from cloud workspace to avoid exceeding quota - curl -X DELETE "$req_url" -H "Authorization: Bearer $SPIPETOOLS_TOKEN" } @test "snapshot mode - query output table" { @@ -79,6 +85,11 @@ function setup() { url=$(grep -o 'http[^"]*' output.txt) echo $url + # create the snapshot DELETE Request URL, so teardown can remove it whatever + # the assertions below do + req_url=$($FILE_PATH/url_parse.sh $url) + echo $req_url + # checking for OS type, since sed command is different for linux and OSX # removing the 18th line, since it contains snapshot upload link, which will be different in each run if [[ "$OSTYPE" == "darwin"* ]]; then @@ -88,14 +99,5 @@ function setup() { fi cat output.txt - # create the snapshot DELETE Request URL - req_url=$($FILE_PATH/url_parse.sh $url) - echo $req_url - assert_equal "$(cat output.txt)" "$(cat $TEST_DATA_DIR/expected_static_query_table_snapshot_mode.txt)" - rm -f output.* - - # delete the snapshot from cloud workspace to avoid exceeding quota - curl -X DELETE "$req_url" -H "Authorization: Bearer $SPIPETOOLS_TOKEN" } -