JSON updates

This commit is contained in:
Olof hagsand 2019-01-20 19:13:40 +01:00
parent 19f26e6838
commit 34d7f60ca4
6 changed files with 81 additions and 17 deletions

View file

@ -193,7 +193,8 @@ EOF
if [ -z "$ret" -a -z "$expect" ]; then
return
fi
# -E for regexp (eg ^$). -Z for nul character, -x for implicit ^$ -q for quiet
# -G for basic regexp (eg ^$). -E for extended regular expression - differs in \
# -Z for nul character, -x for implicit ^$ -q for quiet
# -o only matching
# Two variants: -EZo and -Fxq
# match=`echo "$ret" | grep -FZo "$expect"`

View file

@ -1,15 +1,22 @@
#!/bin/bash
# Test: JSON parser tests
# Note that nmbers shouldnot be quoted. See test_restconf2.sh for typed
#PROG="valgrind --leak-check=full --show-leak-kinds=all ../util/clixon_util_json"
PROG=../util/clixon_util_json
# include err() and new() functions and creates $dir
. ./lib.sh
new "json parse"
expecteof "$PROG" 0 '{"foo": -23}' "^<foo>-23</foo>$"
new "json parse to xml"
expecteofx "$PROG" 0 '{"foo": -23}' "<foo>-23</foo>"
new "json parse list"
expecteof "$PROG" 0 '{"a":[0,1,2,3]}' "^<a>0</a><a>1</a><a>2</a><a>3</a>$"
new "json parse to json" # should be {"foo": -23}
expecteofx "$PROG -j" 0 '{"foo": -23}' '{"foo": "-23"}'
new "json parse list xml"
expecteofx "$PROG" 0 '{"a":[0,1,2,3]}' "<a>0</a><a>1</a><a>2</a><a>3</a>"
new "json parse list json" # should be {"a":[0,1,2,3]}
expecteofx "$PROG -j" 0 '{"a":[0,1,2,3]}' '{"a": "0"}{"a": "1"}{"a": "2"}{"a": "3"}'
rm -rf $dir

View file

@ -44,6 +44,23 @@ module example{
type string;
}
}
container types{
/* A couple of types to test quoting */
leaf tint {
type int32;
}
leaf tdec64 {
type decimal64{
fraction-digits 3;
}
}
leaf tbool {
type boolean;
}
leaf tstr {
type string;
}
}
}
EOF
@ -150,6 +167,13 @@ expectfn 'curl -s -X PUT -d {"interface":{"name":"TEST","type":"eth0"}} http://l
new "restconf PUT change key error"
expectfn 'curl -is -X PUT -d {"interface":{"name":"ALPHA","type":"eth0"}} http://localhost/restconf/data/example:cont1/interface=TEST' 0 '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "operation-failed","error-severity": "error","error-message": "api-path keys do not match data keys"}}}'
#--------------- json type tests
new "restconf POST type x3"
expectfn 'curl -s -X POST -d {"example:types":{"tint":42,"tdec64":42.123,"tbool":false,"tstr":"str"}} http://localhost/restconf/data' 0 ''
new "restconf POST type x3"
expectfn 'curl -s -X GET http://localhost/restconf/data/example:types' 0 '{"example:types": {"tint": 42,"tdec64": 42.123,"tbool": false,"tstr": "str"}}'
new "Kill restconf daemon"
sudo pkill -u www-data -f "/www-data/clixon_restconf"