Skip to content

Commit 80102c5

Browse files
committed
Adding first draft of script to do basic testing of data API routes.
1 parent 832e57a commit 80102c5

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

scripts/test_data_api.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
# Script to do basic testing of data-api
3+
4+
# requires httpie installed
5+
http --version
6+
# test for special value returned when command not found
7+
if [ $? -eq 127 ]
8+
then
9+
echo "Error: httpie must be involved."
10+
echo "install via: sudo apt install httpie"
11+
else
12+
echo "httpie is installed, continuing"
13+
fi
14+
# test all the routes of the data API to be sure they respond
15+
# reference: idb-backend/blob/master/idb/data_api/config.py
16+
SUPPORTED_TYPES=( "recordsets" "records" "publishers" "mediarecords" )
17+
base_url="api.idigbio.org"
18+
api_version="v2"
19+
20+
if [ "$1" == 'beta' ]
21+
then
22+
env='beta'
23+
hostname='beta-api'
24+
else
25+
if [ "$1" == 'prod' ]
26+
then
27+
env='prod'
28+
hostname='api'
29+
else
30+
echo "Error: please specify prod or beta environment for testing"
31+
echo "call script like this: ./test_data_api.sh beta"
32+
exit
33+
fi
34+
fi
35+
36+
route="view"
37+
testing_route="${hostname}.idigbio.org/$api_version/$route/"
38+
for i in "${SUPPORTED_TYPES[@]}"
39+
do
40+
testing_url=${testing_route}$i
41+
echo "testing $testing_url"
42+
if http --check-status --ignore-stdin $testing_url &> /dev/null;
43+
then
44+
echo 'OK!'
45+
else
46+
case $? in
47+
2) echo 'Request timed out!' ;;
48+
3) echo 'Unexpected HTTP 3xx Redirection!' ;;
49+
4) echo 'HTTP 4xx Client Error!' ;;
50+
5) echo 'HTTP 5xx Server Error!' ;;
51+
6) echo 'Exceeded --max-redirects=<n> redirects!' ;;
52+
*) echo 'Other Error!' ;;
53+
esac
54+
fi
55+
done
56+
echo "Completed testing."

0 commit comments

Comments
 (0)