github.com/leg100/ots@v0.0.7-0.20210919080622-034055ced4bd/hack/harness.bash (about) 1 #!/usr/bin/env bash 2 3 # A test harness for otsd. It'll first check if otsd is running. If it 4 # is not running it'll start otsd before the tests, and terminate 5 # it afterwards (Often a developer instead runs otsd in another 6 # terminal...). 7 8 9 set -x 10 11 export PATH=$PWD/_build:$PATH 12 13 export OTS_SSL=true 14 export OTS_CERT_FILE=./e2e/fixtures/cert.crt 15 export OTS_KEY_FILE=./e2e/fixtures/key.pem 16 export OTS_DB_PATH=$(mktemp) 17 18 # Track whether this script started otsd 19 started=0 20 21 # Upon exit, stop otsd if this script started it 22 function cleanup() 23 { 24 if [[ $started -eq 1 ]]; then 25 pkill otsd 26 fi 27 } 28 trap cleanup EXIT 29 30 # Upon error, print out otsd logs (...but only if this script started it), 31 # and exit 32 function print_logs() 33 { 34 if [[ $started -eq 1 ]]; then 35 echo "--- otsd output ---" 36 echo 37 cat otsd.log 38 fi 39 } 40 trap print_logs ERR 41 42 # Start otsd if not already running 43 if ! pgrep otsd; then 44 nohup otsd > otsd.log & 45 started=1 46 fi 47 48 # Wait til it's running 49 curl \ 50 --retry 5 \ 51 --retry-connrefused \ 52 -H'Accept: application/vnd.api+json' \ 53 https://localhost:8080/api/v2/ping 54 55 # Run tests... 56 $@