-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.sh
executable file
·49 lines (39 loc) · 1.23 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
PORT=9091
SAMPLE_URL="http://example.org/fileadmin/digi/445442158/thumbs/445442158_0126.jpg"
SAMPLE_THUMB="example/fileadmin/digi/445442158/thumbs/445442158_0126.jpg"
SAMPLE_CORR="example/ocr-corrections/digi/445442158/gt/0126/correction.html"
SAMPLE_COMM="example/ocr-corrections/digi/445442158/gt/0126/anmerkungen.txt"
# rm request log files, samples, start the server, wait a second, see if it's still running
start_server() {
rm -f dist/log/* $SAMPLE_COMM $SAMPLE_CORR
plackup --port=$PORT app.psgi & SERVER_PID=$!
sleep 1
ps -p "$SERVER_PID" 2>/dev/null
}
stop_server() {
kill "$SERVER_PID" && true
cat dist/log/ocr-gt-tools.log
}
# Test history
test_history() {
curl -i "http://localhost:$PORT/ocr-gt-tools.cgi?action=history"
[[ "$(wc -l dist/log/request.log|cut -d' ' -f1)" = "1" ]];
}
# Test create
test_create() {
[[ ! -e $SAMPLE_COMM ]];
[[ ! -e $SAMPLE_CORR ]];
curl -i "http://localhost:$PORT/ocr-gt-tools.cgi?action=create&imageUrl=$SAMPLE_URL"
[[ -e $SAMPLE_COMM ]];
[[ -e $SAMPLE_CORR ]];
}
# -x Trace steps
# -e exit on first non-null return value
set -e
# Stop the server for failing tests
trap stop_server EXIT
start_server
test_create
test_history
stop_server