summaryrefslogtreecommitdiff
path: root/tests/run-tests.sh
diff options
context:
space:
mode:
authorQuentin Aristote <quentin@aristote.fr>2021-11-26 22:57:12 +0100
committerQuentin Aristote <quentin@aristote.fr>2021-11-26 22:57:12 +0100
commit2f082be4a383fe163e3d008af98eac22611b13c0 (patch)
tree4b5acf1e7cfd08644acf1fbed6ec292e5d69bbd3 /tests/run-tests.sh
parent0e3b0116595017f599d540725cde43de09bcaf19 (diff)
improve test script
Diffstat (limited to 'tests/run-tests.sh')
-rwxr-xr-x[-rw-r--r--]tests/run-tests.sh56
1 files changed, 52 insertions, 4 deletions
diff --git a/tests/run-tests.sh b/tests/run-tests.sh
index 52f4a1e..a1404fc 100644..100755
--- a/tests/run-tests.sh
+++ b/tests/run-tests.sh
@@ -1,13 +1,61 @@
#! /usr/bin/env nix-shell
-#! nix-shell --packages curl
+#! nix-shell -i bash -p jq curl
+
+function cleanup {
+ echo
+ echo Shutting down container ...
+ sudo nixos-container stop hermes
+}
sudo nixos-container update hermes --config-file ./vm.nix || exit 2
+echo Starting container ...
sudo nixos-container start hermes || exit 2
+trap cleanup EXIT
+sleep 0.1
IP=$(nixos-container show-ip hermes)
-for PORT in 8080 8081 8082
+
+echo
+echo Checking that all the services are running :
+declare -A PORTS
+PORTS[quentin]=8080
+PORTS[searx]=8081
+PORTS[money]=8082
+CURL_FLAGS='--location --silent'
+for SERVICE in "${!PORTS[@]}"
do
- curl http://$IP:$PORT/ -i || exit 2
+ echo Checking connection to container version of $SERVICE.aristote.fr ...
+ RESULT=$(curl "http://$IP:${PORTS[$SERVICE]}/" $CURL_FLAGS --output /dev/null --write-out '%{http_code}\n')
+ if [[ ! "$RESULT" = 200 ]]
+ then
+ echo "Connection failed."
+ exit 2
+ fi
done
+echo Done.
-sudo nixos-container stop hermes
+echo
+echo Checking custom Searx engines :
+declare -A QUERIES
+QUERIES[alternativeto]=Searx
+QUERIES[emojipedia]=',,,,,,,,,,,,' #'Thinking%20face'
+QUERIES[nlab]='Kan%20extension'
+QUERIES[wikipediafr]=Paris
+QUERIES[wikipediaen]=Paris
+for ENGINE in "${!QUERIES[@]}"
+do
+ echo Checking engine $ENGINE ...
+ JSON_RESULT=$(curl "http://$IP:${PORTS[searx]}/search?q=${QUERIES[$ENGINE]}+\!$ENGINE&format=json" $CURL_FLAGS)
+ RESULTS=$(echo $JSON_RESULT | jq '.results')
+ UNRESPONSIVE_ENGINES=$(echo $JSON_RESULT | jq '.unresponsive_engines')
+ if [[ ! "$UNRESPONSIVE_ENGINES" = '[]' ]]
+ then
+ echo "Engine not responsive."
+ exit 2
+ elif [[ "RESULTS" = [] ]]
+ then
+ echo "No results found."
+ exit 2
+ fi
+done
+echo Done.