From 185ed832d4554f94929d5721d1d88fc9ba5246b7 Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Wed, 24 Jul 2024 19:10:08 -0400 Subject: [PATCH] run tests via nimble --- tests/{test-image.png => image.png} | Bin tests/test.nim | 7 +++++++ tests/test_1.sh | 27 +++++++++++++++------------ 3 files changed, 22 insertions(+), 12 deletions(-) rename tests/{test-image.png => image.png} (100%) create mode 100644 tests/test.nim diff --git a/tests/test-image.png b/tests/image.png similarity index 100% rename from tests/test-image.png rename to tests/image.png diff --git a/tests/test.nim b/tests/test.nim new file mode 100644 index 0000000..ec67ea0 --- /dev/null +++ b/tests/test.nim @@ -0,0 +1,7 @@ +import std/[unittest, os, osproc] + +test "Run tests": + copyFile("./tests/image.png", "./image.png") + if execCmd("cd tests && bash -c ./test_1.sh") > 0: + fail() + removeFile("./image.png") \ No newline at end of file diff --git a/tests/test_1.sh b/tests/test_1.sh index d8df8b9..4e07f73 100755 --- a/tests/test_1.sh +++ b/tests/test_1.sh @@ -11,6 +11,7 @@ CLR='\033[0m' CONFIGFILE="../config.ini" PASSWORD=$(pwgen 50 1) +ERR=0 if grep -q ^bindAddr $CONFIGFILE; then BINDADDR=$(grep ^bindAddr $CONFIGFILE | tr -d '"' | tr -d '[:blank:]' | cut -c 10-) @@ -30,37 +31,39 @@ ENDPOINT="/api/v1/newUser" printf "\n%bTest: $ENDPOINT%b\n" "$BLD" "$CLR" -curl -X POST http://"$BINDADDR":"$PORT""$ENDPOINT" \ - -d "username=testUser" -d "password=$PASSWORD" \ - -d "email=test@example.xyz" | jq -M +curl -S --fail-early -X POST http://"$BINDADDR":"$PORT""$ENDPOINT" \ + -d "username=testUser" -d "password=$PASSWORD" \ + -d "email=test@example.xyz" if test $? -eq 0; then printf "%bTest: Success - $ENDPOINT" "$YAY"; -else printf "%bTest: Fail - $ENDPOINT" "$NAY"; +else printf "%bTest: Fail - $ENDPOINT" "$NAY"; ((ERROR++)); fi; printf "%b\n" "$CLR"; ENDPOINT="/api/v1/newSession" printf "\n%bTest: $ENDPOINT%b\n" "$BLD" "$CLR" -TOKEN=$(curl -s -X POST http://"$BINDADDR":"$PORT""/api/v1/newUser" -d "username=testUser1" -d "password=$PASSWORD" -d "email=test@example.xyz" | jq -M ".[0].token" | tr -d '"') +TOKEN=$(curl -S --fail-early -X POST http://"$BINDADDR":"$PORT""/api/v1/newUser" -d "username=testUser1" -d "password=$PASSWORD" -d "email=test@example.xyz" | jq ".[0].token" | tr -d '"') -curl -X GET http://"$BINDADDR":"$PORT""$ENDPOINT" \ - -H "Authorization: $TOKEN" | jq -M +curl -S --fail-early -X GET http://"$BINDADDR":"$PORT""$ENDPOINT" \ + -H "Authorization: $TOKEN" if test $? -eq 0; then printf "%bTest: Success - $ENDPOINT" "$YAY"; -else printf "%bTest: Fail - $ENDPOINT" "$NAY"; +else printf "%bTest: Fail - $ENDPOINT" "$NAY"; ((ERROR++)); fi; printf "%b\n" "$CLR"; ENDPOINT="/api/v1/newFile" printf "\n%bTest: $ENDPOINT%b\n" "$BLD" "$CLR" -TOKEN=$(curl -s -X POST http://"$BINDADDR":"$PORT""/api/v1/newUser" -d "username=testUser2" -d "password=$PASSWORD" -d "email=test@example.xyz" | jq -M ".[0].token" | tr -d '"') +TOKEN=$(curl -S --fail-early -X POST http://"$BINDADDR":"$PORT""/api/v1/newUser" -d "username=testUser2" -d "password=$PASSWORD" -d "email=test@example.xyz" | jq ".[0].token" | tr -d '"') -curl -X POST http://"$BINDADDR":"$PORT""$ENDPOINT" \ - -H "Authorization: $TOKEN" -F "file=@test-image.png" +curl -S --fail-early -X POST http://"$BINDADDR":"$PORT""$ENDPOINT" \ + -H "Authorization: $TOKEN" -F "file=@image.png" if test $? -eq 0; then printf "%bTest: Success - $ENDPOINT" "$YAY"; -else printf "%bTest: Fail - $ENDPOINT" "$NAY"; +else printf "%bTest: Fail - $ENDPOINT" "$NAY"; ((ERROR++)); fi; printf "%b\n" "$CLR"; + +exit $ERROR; \ No newline at end of file