Statistics
| Branch: | Tag: | Revision:

mongoose / examples / api_server / unit_test.sh @ eaef5bd1

History | View | Annotate | Download (670 Bytes)

1
#!/bin/sh
2

    
3
PROG=$1
4
PORT=${2:-8000}  # If second param is given, this is load balancer port
5
DB_FILE=/tmp/_$$.db
6
URL=http://127.0.0.1:$PORT/api/v1
7

    
8
cleanup() {
9
  rm -rf $DB_FILE
10
  kill -9 $PID >/dev/null 2>&1
11
}
12

    
13
#set -x
14
trap cleanup EXIT
15

    
16
cleanup
17
$PROG -f $DB_FILE &
18
PID=$!
19

    
20
#sleep 1
21
curl -s -X PUT -d 'value=123' $URL/foo
22
curl -s -X PUT -d 'value=success' $URL/bar/baz
23

    
24
# Fetch existing key
25
RESULT=$(curl -s $URL/bar/baz)
26
test "$RESULT" = "success" || exit 1
27

    
28
# Delete it
29
curl -s -X DELETE $URL/bar/baz
30

    
31
# Make sure it's deleted - GET must result in 404
32
RESULT=$(curl -s -i $URL/bar/baz | head -1 | tr -d '\r')
33
test "$RESULT" = "HTTP/1.1 404 Not Found" || exit 1
34

    
35
exit 0