From c60090d461736de16dc66927f1e81d5034d5ede0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sat, 21 May 2022 16:43:32 +0300 Subject: [PATCH] fix(fixtures): exit the run_test function on error --- fixtures/README.md | 4 ++-- fixtures/test-duplicate-file-upload/test.sh | 4 ++-- fixtures/test-expiring-file-upload/test.sh | 4 ++-- fixtures/test-file-upload/test.sh | 4 ++-- fixtures/test-oneshot-upload/test.sh | 4 ++-- fixtures/test-path-traversal/test.sh | 4 ++-- fixtures/test-remote-file-upload/test.sh | 4 ++-- fixtures/test-server-auth/test.sh | 4 ++-- fixtures/test-server-payload-limit/test.sh | 4 ++-- fixtures/test-url-upload/test.sh | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/fixtures/README.md b/fixtures/README.md index 023af52..7a6bf22 100644 --- a/fixtures/README.md +++ b/fixtures/README.md @@ -29,9 +29,9 @@ setup() { # preparation } -run_test() { +run_test() ( set -e; # assertions -} +) teardown() { # cleanup diff --git a/fixtures/test-duplicate-file-upload/test.sh b/fixtures/test-duplicate-file-upload/test.sh index 935e4d1..86d938b 100755 --- a/fixtures/test-duplicate-file-upload/test.sh +++ b/fixtures/test-duplicate-file-upload/test.sh @@ -9,7 +9,7 @@ setup() { date +%s > unique_file2 } -run_test() { +run_test() ( set -e; first_file_url=$(curl -s -F "file=@file" localhost:8000) test "$duplicate_content" = "$(cat upload/file.txt)" @@ -22,7 +22,7 @@ run_test() { first_file_url=$(curl -s -F "file=@unique_file1" localhost:8000) second_file_url=$(curl -s -F "file=@unique_file2" localhost:8000) test "$first_file_url" != "$second_file_url" -} +) teardown() { rm file unique_file1 unique_file2 diff --git a/fixtures/test-expiring-file-upload/test.sh b/fixtures/test-expiring-file-upload/test.sh index a05eeae..ebdf962 100755 --- a/fixtures/test-expiring-file-upload/test.sh +++ b/fixtures/test-expiring-file-upload/test.sh @@ -6,14 +6,14 @@ setup() { echo "$content" > file } -run_test() { +run_test() ( set -e; file_url=$(curl -s -F "file=@file" -H "expire:1s" localhost:8000) test "$content" = "$(cat upload/file.txt.*)" sleep 2s result="$(curl -s $file_url)" test "file is not found or expired :(" = "$result" -} +) teardown() { rm file diff --git a/fixtures/test-file-upload/test.sh b/fixtures/test-file-upload/test.sh index 797074e..fe25d8a 100755 --- a/fixtures/test-file-upload/test.sh +++ b/fixtures/test-file-upload/test.sh @@ -6,12 +6,12 @@ setup() { echo "$content" > file } -run_test() { +run_test() ( set -e; file_url=$(curl -s -F "file=@file" localhost:8000) test "$file_url" = "http://localhost:8000/file.txt" test "$content" = "$(cat upload/file.txt)" test "$content" = "$(curl -s $file_url)" -} +) teardown() { rm file diff --git a/fixtures/test-oneshot-upload/test.sh b/fixtures/test-oneshot-upload/test.sh index 64c9a6a..99addc5 100755 --- a/fixtures/test-oneshot-upload/test.sh +++ b/fixtures/test-oneshot-upload/test.sh @@ -6,14 +6,14 @@ setup() { echo "$content" > file } -run_test() { +run_test() ( set -e; file_url=$(curl -s -F "oneshot=@file" localhost:8000) test "$content" = $(curl -s "$file_url") test "$content" = "$(cat upload/oneshot/file.txt.*)" result="$(curl -s $file_url)" test "file is not found or expired :(" = "$result" -} +) teardown() { rm file diff --git a/fixtures/test-path-traversal/test.sh b/fixtures/test-path-traversal/test.sh index 6190b70..9c70d7d 100755 --- a/fixtures/test-path-traversal/test.sh +++ b/fixtures/test-path-traversal/test.sh @@ -6,7 +6,7 @@ setup() { echo "$content" > file } -run_test() { +run_test() ( set -e; result=$(curl -s --path-as-is localhost:8000/.) test "file is not found or expired :(" = "$result" @@ -15,7 +15,7 @@ run_test() { result=$(curl -s -X POST -F "file=@file;filename=../." localhost:8000) test "$content" = "$(cat upload/file.txt)" -} +) teardown() { rm file diff --git a/fixtures/test-remote-file-upload/test.sh b/fixtures/test-remote-file-upload/test.sh index ed6a3c8..a7eab16 100755 --- a/fixtures/test-remote-file-upload/test.sh +++ b/fixtures/test-remote-file-upload/test.sh @@ -6,12 +6,12 @@ setup() { :; } -run_test() { +run_test() ( set -e; file_url=$(curl -s -F "remote=$url" localhost:8000) curl -s "$file_url" -o uploaded_file > /dev/null curl -s "$url" -o remote_file > /dev/null test "$(sha256sum uploaded_file | awk '{print $1}')" = "$(sha256sum remote_file | awk '{print $1}')" -} +) teardown() { rm uploaded_file remote_file diff --git a/fixtures/test-server-auth/test.sh b/fixtures/test-server-auth/test.sh index 154ed26..f75fa6f 100755 --- a/fixtures/test-server-auth/test.sh +++ b/fixtures/test-server-auth/test.sh @@ -7,7 +7,7 @@ setup() { echo "$content" > file } -run_test() { +run_test() ( set -e; result=$(curl -s -F "file=@file" localhost:8000) test "unauthorized" = "$result" @@ -15,7 +15,7 @@ run_test() { test "unauthorized" != "$result" test "$content" = "$(cat upload/file.txt)" test "$content" = "$(curl -s $result)" -} +) teardown() { rm file diff --git a/fixtures/test-server-payload-limit/test.sh b/fixtures/test-server-payload-limit/test.sh index d0670e3..f591687 100755 --- a/fixtures/test-server-payload-limit/test.sh +++ b/fixtures/test-server-payload-limit/test.sh @@ -7,7 +7,7 @@ setup() { truncate -s 11KB bigfile } -run_test() { +run_test() ( set -e; result=$(curl -s -F "file=@emptyfile" localhost:8000) test "invalid file size" = "$result" @@ -19,7 +19,7 @@ run_test() { result=$(curl -s -F "file=@smallfile" localhost:8000) test "upload limit exceeded" != "$result" -} +) teardown() { rm emptyfile smallfile normalfile bigfile diff --git a/fixtures/test-url-upload/test.sh b/fixtures/test-url-upload/test.sh index 55e73a8..001e203 100755 --- a/fixtures/test-url-upload/test.sh +++ b/fixtures/test-url-upload/test.sh @@ -6,13 +6,13 @@ setup() { :; } -run_test() { +run_test() ( set -e; curl -s -F "url=$url" localhost:8000 > /dev/null test "$url" = "$(cat upload/url/url)" result=$(curl -s -F "url=invalidurl" localhost:8000) test "relative URL without a base" = "$result" -} +) teardown() { rm -r upload