mirror of
https://github.com/glimpse-app/server.git
synced 2025-04-02 10:52:45 -04:00
run tests via nimble
This commit is contained in:
parent
168e6592b1
commit
185ed832d4
3 changed files with 22 additions and 12 deletions
Before Width: | Height: | Size: 201 KiB After Width: | Height: | Size: 201 KiB |
7
tests/test.nim
Normal file
7
tests/test.nim
Normal 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")
|
|
@ -11,6 +11,7 @@ CLR='\033[0m'
|
||||||
|
|
||||||
CONFIGFILE="../config.ini"
|
CONFIGFILE="../config.ini"
|
||||||
PASSWORD=$(pwgen 50 1)
|
PASSWORD=$(pwgen 50 1)
|
||||||
|
ERR=0
|
||||||
|
|
||||||
if grep -q ^bindAddr $CONFIGFILE; then
|
if grep -q ^bindAddr $CONFIGFILE; then
|
||||||
BINDADDR=$(grep ^bindAddr $CONFIGFILE | tr -d '"' | tr -d '[:blank:]' | cut -c 10-)
|
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"
|
printf "\n%bTest: $ENDPOINT%b\n" "$BLD" "$CLR"
|
||||||
|
|
||||||
curl -X POST http://"$BINDADDR":"$PORT""$ENDPOINT" \
|
curl -S --fail-early -X POST http://"$BINDADDR":"$PORT""$ENDPOINT" \
|
||||||
-d "username=testUser" -d "password=$PASSWORD" \
|
-d "username=testUser" -d "password=$PASSWORD" \
|
||||||
-d "email=test@example.xyz" | jq -M
|
-d "email=test@example.xyz"
|
||||||
|
|
||||||
if test $? -eq 0; then printf "%bTest: Success - $ENDPOINT" "$YAY";
|
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";
|
fi; printf "%b\n" "$CLR";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ENDPOINT="/api/v1/newSession"
|
ENDPOINT="/api/v1/newSession"
|
||||||
printf "\n%bTest: $ENDPOINT%b\n" "$BLD" "$CLR"
|
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" \
|
curl -S --fail-early -X GET http://"$BINDADDR":"$PORT""$ENDPOINT" \
|
||||||
-H "Authorization: $TOKEN" | jq -M
|
-H "Authorization: $TOKEN"
|
||||||
|
|
||||||
if test $? -eq 0; then printf "%bTest: Success - $ENDPOINT" "$YAY";
|
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";
|
fi; printf "%b\n" "$CLR";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ENDPOINT="/api/v1/newFile"
|
ENDPOINT="/api/v1/newFile"
|
||||||
printf "\n%bTest: $ENDPOINT%b\n" "$BLD" "$CLR"
|
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" \
|
curl -S --fail-early -X POST http://"$BINDADDR":"$PORT""$ENDPOINT" \
|
||||||
-H "Authorization: $TOKEN" -F "file=@test-image.png"
|
-H "Authorization: $TOKEN" -F "file=@image.png"
|
||||||
|
|
||||||
if test $? -eq 0; then printf "%bTest: Success - $ENDPOINT" "$YAY";
|
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";
|
fi; printf "%b\n" "$CLR";
|
||||||
|
|
||||||
|
|
||||||
|
exit $ERROR;
|
Loading…
Add table
Reference in a new issue