run tests via nimble

This commit is contained in:
array-in-a-matrix 2024-07-24 19:10:08 -04:00
parent 168e6592b1
commit 185ed832d4
3 changed files with 22 additions and 12 deletions

View file

Before

Width:  |  Height:  |  Size: 201 KiB

After

Width:  |  Height:  |  Size: 201 KiB

7
tests/test.nim Normal file
View file

@ -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")

View file

@ -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;