Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions tests/acceptance/test_files/snapshot.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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
Expand All @@ -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" {
Expand All @@ -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
Expand All @@ -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" {
Expand All @@ -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
Expand All @@ -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"
}

Loading