comparison test/test-server.sh @ 143:a9be6f1e680d

Don't try to validate if schema dir not found (avoiding lengthy errors)
author Chris Cannam <c.cannam@qmul.ac.uk>
date Wed, 18 Jan 2017 14:19:12 +0000
parents 3ae0335cfe60
children
comparison
equal deleted inserted replaced
142:9768b5ca710a 143:a9be6f1e680d
3 set -eu 3 set -eu
4 4
5 piperdir=../piper 5 piperdir=../piper
6 vampsdkdir=../vamp-plugin-sdk 6 vampsdkdir=../vamp-plugin-sdk
7 schemadir="$piperdir"/json/schema 7 schemadir="$piperdir"/json/schema
8
9 if [ ! -d "$schemadir" ]; then
10 echo "WARNING: schema directory $schemadir not found, won't be validating JSON schema" 1>&2
11 fi
8 12
9 tmpdir=$(mktemp -d) 13 tmpdir=$(mktemp -d)
10 14
11 if [ ! -d "$tmpdir" ]; then 15 if [ ! -d "$tmpdir" ]; then
12 echo "Temp directory creation failed" 1>&2 16 echo "Temp directory creation failed" 1>&2
23 obtained="$tmpdir/obtained" 27 obtained="$tmpdir/obtained"
24 28
25 validate() { 29 validate() {
26 local file="$1" 30 local file="$1"
27 local schemaname="$2" 31 local schemaname="$2"
28 jsonschema -i "$file" "$schemadir/$schemaname.json" 1>&2 && \ 32 if [ -d "$schemadir" ]; then
29 echo "validated $schemaname" 1>&2 || \ 33 jsonschema -i "$file" "$schemadir/$schemaname.json" 1>&2 && \
30 echo "failed to validate $schemaname" 1>&2 34 echo "validated $schemaname" 1>&2 || \
35 echo "failed to validate $schemaname" 1>&2
36 else
37 echo "schema directory $schemadir not found, skipping validation" 1>&2
38 fi
31 } 39 }
32 40
33 validate_request() { 41 validate_request() {
34 local json="$1" 42 local json="$1"
35 echo "$json" > "$reqfile" 43 echo "$json" > "$reqfile"