refactor(fixtures): use subshell for running fixture methods

This commit is contained in:
Orhun Parmaksız 2022-05-21 16:49:10 +03:00
parent c60090d461
commit cccbf98acc
No known key found for this signature in database
GPG key ID: F83424824B3E4B90
11 changed files with 23 additions and 23 deletions

View file

@ -29,9 +29,9 @@ setup() {
# preparation # preparation
} }
run_test() ( set -e; run_test() {
# assertions # assertions
) }
teardown() { teardown() {
# cleanup # cleanup

View file

@ -9,7 +9,7 @@ setup() {
date +%s > unique_file2 date +%s > unique_file2
} }
run_test() ( set -e; run_test() {
first_file_url=$(curl -s -F "file=@file" localhost:8000) first_file_url=$(curl -s -F "file=@file" localhost:8000)
test "$duplicate_content" = "$(cat upload/file.txt)" test "$duplicate_content" = "$(cat upload/file.txt)"
@ -22,7 +22,7 @@ run_test() ( set -e;
first_file_url=$(curl -s -F "file=@unique_file1" localhost:8000) first_file_url=$(curl -s -F "file=@unique_file1" localhost:8000)
second_file_url=$(curl -s -F "file=@unique_file2" localhost:8000) second_file_url=$(curl -s -F "file=@unique_file2" localhost:8000)
test "$first_file_url" != "$second_file_url" test "$first_file_url" != "$second_file_url"
) }
teardown() { teardown() {
rm file unique_file1 unique_file2 rm file unique_file1 unique_file2

View file

@ -6,14 +6,14 @@ setup() {
echo "$content" > file echo "$content" > file
} }
run_test() ( set -e; run_test() {
file_url=$(curl -s -F "file=@file" -H "expire:1s" localhost:8000) file_url=$(curl -s -F "file=@file" -H "expire:1s" localhost:8000)
test "$content" = "$(cat upload/file.txt.*)" test "$content" = "$(cat upload/file.txt.*)"
sleep 2s sleep 2s
result="$(curl -s $file_url)" result="$(curl -s $file_url)"
test "file is not found or expired :(" = "$result" test "file is not found or expired :(" = "$result"
) }
teardown() { teardown() {
rm file rm file

View file

@ -6,12 +6,12 @@ setup() {
echo "$content" > file echo "$content" > file
} }
run_test() ( set -e; run_test() {
file_url=$(curl -s -F "file=@file" localhost:8000) file_url=$(curl -s -F "file=@file" localhost:8000)
test "$file_url" = "http://localhost:8000/file.txt" test "$file_url" = "http://localhost:8000/file.txt"
test "$content" = "$(cat upload/file.txt)" test "$content" = "$(cat upload/file.txt)"
test "$content" = "$(curl -s $file_url)" test "$content" = "$(curl -s $file_url)"
) }
teardown() { teardown() {
rm file rm file

View file

@ -13,10 +13,10 @@ run_fixture() {
SERVER_PID=$! SERVER_PID=$!
trap 'kill -9 "$SERVER_PID" && wait "$SERVER_PID" 2> /dev/null' RETURN trap 'kill -9 "$SERVER_PID" && wait "$SERVER_PID" 2> /dev/null' RETURN
sleep 1 sleep 1
setup ( set -e; setup )
run_test ( set -e; run_test )
result=$? result=$?
teardown ( set -e; teardown )
return "$result" return "$result"
} }

View file

@ -6,14 +6,14 @@ setup() {
echo "$content" > file echo "$content" > file
} }
run_test() ( set -e; run_test() {
file_url=$(curl -s -F "oneshot=@file" localhost:8000) file_url=$(curl -s -F "oneshot=@file" localhost:8000)
test "$content" = $(curl -s "$file_url") test "$content" = $(curl -s "$file_url")
test "$content" = "$(cat upload/oneshot/file.txt.*)" test "$content" = "$(cat upload/oneshot/file.txt.*)"
result="$(curl -s $file_url)" result="$(curl -s $file_url)"
test "file is not found or expired :(" = "$result" test "file is not found or expired :(" = "$result"
) }
teardown() { teardown() {
rm file rm file

View file

@ -6,7 +6,7 @@ setup() {
echo "$content" > file echo "$content" > file
} }
run_test() ( set -e; run_test() {
result=$(curl -s --path-as-is localhost:8000/.) result=$(curl -s --path-as-is localhost:8000/.)
test "file is not found or expired :(" = "$result" test "file is not found or expired :(" = "$result"
@ -15,7 +15,7 @@ run_test() ( set -e;
result=$(curl -s -X POST -F "file=@file;filename=../." localhost:8000) result=$(curl -s -X POST -F "file=@file;filename=../." localhost:8000)
test "$content" = "$(cat upload/file.txt)" test "$content" = "$(cat upload/file.txt)"
) }
teardown() { teardown() {
rm file rm file

View file

@ -6,12 +6,12 @@ setup() {
:; :;
} }
run_test() ( set -e; run_test() {
file_url=$(curl -s -F "remote=$url" localhost:8000) file_url=$(curl -s -F "remote=$url" localhost:8000)
curl -s "$file_url" -o uploaded_file > /dev/null curl -s "$file_url" -o uploaded_file > /dev/null
curl -s "$url" -o remote_file > /dev/null curl -s "$url" -o remote_file > /dev/null
test "$(sha256sum uploaded_file | awk '{print $1}')" = "$(sha256sum remote_file | awk '{print $1}')" test "$(sha256sum uploaded_file | awk '{print $1}')" = "$(sha256sum remote_file | awk '{print $1}')"
) }
teardown() { teardown() {
rm uploaded_file remote_file rm uploaded_file remote_file

View file

@ -7,7 +7,7 @@ setup() {
echo "$content" > file echo "$content" > file
} }
run_test() ( set -e; run_test() {
result=$(curl -s -F "file=@file" localhost:8000) result=$(curl -s -F "file=@file" localhost:8000)
test "unauthorized" = "$result" test "unauthorized" = "$result"
@ -15,7 +15,7 @@ run_test() ( set -e;
test "unauthorized" != "$result" test "unauthorized" != "$result"
test "$content" = "$(cat upload/file.txt)" test "$content" = "$(cat upload/file.txt)"
test "$content" = "$(curl -s $result)" test "$content" = "$(curl -s $result)"
) }
teardown() { teardown() {
rm file rm file

View file

@ -7,7 +7,7 @@ setup() {
truncate -s 11KB bigfile truncate -s 11KB bigfile
} }
run_test() ( set -e; run_test() {
result=$(curl -s -F "file=@emptyfile" localhost:8000) result=$(curl -s -F "file=@emptyfile" localhost:8000)
test "invalid file size" = "$result" test "invalid file size" = "$result"
@ -19,7 +19,7 @@ run_test() ( set -e;
result=$(curl -s -F "file=@smallfile" localhost:8000) result=$(curl -s -F "file=@smallfile" localhost:8000)
test "upload limit exceeded" != "$result" test "upload limit exceeded" != "$result"
) }
teardown() { teardown() {
rm emptyfile smallfile normalfile bigfile rm emptyfile smallfile normalfile bigfile

View file

@ -6,13 +6,13 @@ setup() {
:; :;
} }
run_test() ( set -e; run_test() {
curl -s -F "url=$url" localhost:8000 > /dev/null curl -s -F "url=$url" localhost:8000 > /dev/null
test "$url" = "$(cat upload/url/url)" test "$url" = "$(cat upload/url/url)"
result=$(curl -s -F "url=invalidurl" localhost:8000) result=$(curl -s -F "url=invalidurl" localhost:8000)
test "relative URL without a base" = "$result" test "relative URL without a base" = "$result"
) }
teardown() { teardown() {
rm -r upload rm -r upload