From b96ba3eb34d5dd32e59304d28fcff00640d1f4b1 Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Sat, 28 Dec 2024 12:50:32 +0200 Subject: [PATCH] add automated testing script for user table --- tests/lab3/user_test.sh | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 tests/lab3/user_test.sh diff --git a/tests/lab3/user_test.sh b/tests/lab3/user_test.sh new file mode 100755 index 0000000..82f5c5e --- /dev/null +++ b/tests/lab3/user_test.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +HOST=$1 + +if [ -z HOST ]; then + echo "Host not specified, exiting" + exit 1; +fi; + +echo -n 'Resetting DB...' + +curl -X GET -f -s \ + http://$HOST:12402/reset_users_because_postman_is_dumb_like_that > /dev/null + +if [ $? -ne 0 ]; then + echo 'Exiting due to previous error' + exit 1 +fi +echo ' Done.' + +echo -n 'Creating users...' +for i in $(seq 9); do + curl -X POST -f -s \ + --data "{\"name\": \"hi$i\"}" \ + --header "Content-Type: application/json" \ + http://$HOST:12402/user > /dev/null; + + if [ $? -ne 0 ]; then + echo 'Exiting due to previous error' + exit 1 + fi +done +echo ' Done.' + +echo -n 'Getting user UUID to delete...' +DELETION_UUID=$(curl -X GET -f -s \ + http://$HOST:12402/users \ + | jq .[0].uuid); + +if [ $? -ne 0 ]; then + echo 'Exiting due to previous error' + exit 1 +fi + +DELETION_UUID=${DELETION_UUID#\"} +DELETION_UUID=${DELETION_UUID%\"} + +echo " $DELETION_UUID." + +echo -n "Deleting user $DELETION_UUID..." +curl -X DELETE -f -s \ + http://127.0.0.1:12402/user/$DELETION_UUID > /dev/null + +if [ $? -ne 0 ]; then + echo 'Exiting due to previous error' + exit 1 +fi +echo ' Done.'