#!/usr/bin/env bash
# Test netconf / xml whitespaces
# Insignicant and significant
# See https://www.w3.org/TR/xml-c14n
# where "clean", "dirty" and "mixed" whitespaces are defined
#
# A B
#
# A
#
# B
# A B
# C
#
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example
cfg=$dir/conf_yang.xml
fyang=$dir/whitespace.yang
cat < $cfg
$cfg
ietf-netconf:startup
/usr/local/share/clixon
$fyang
/usr/local/lib/$APPNAME/clispec
/usr/local/lib/$APPNAME/cli
$APPNAME
/usr/local/var/$APPNAME/$APPNAME.sock
/usr/local/lib/$APPNAME/backend
/usr/local/var/$APPNAME/$APPNAME.pidfile
$dir
EOF
cat < $fyang
module whitespace{
yang-version 1.1;
namespace "urn:example:whitespace";
prefix fi;
container x{
presence true;
list y {
key a;
leaf a{
type string;
}
container b{
presence true;
}
}
}
}
EOF
new "test params: -f $cfg -s startup"
echo '
foo\n ]]>]]>$start' > $dir/startup_db
if [ $BE -ne 0 ]; then
new "kill old backend"
sudo clixon_backend -zf $cfg -s startup
if [ $? -ne 0 ]; then
err
fi
new "start backend -s startup -f $cfg"
start_backend -s startup -f $cfg
fi
new "waiting"
wait_backend
new "get startup"
expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^foo]]>]]>$'
new "remove"
expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^]]>]]>$'
new "commit"
expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$"
new "add insignificant 'dirty' whitespaces"
expecteof "$clixon_netconf -qf $cfg" 0 ' \t \ foo\n ]]>]]>' '^]]>]]>$'
new "get stripped whitespace"
expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^foo]]>]]>$'
new "validate"
expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$"
new "netconf discard-changes"
expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$"
new "add insignificant 'dirty' whitespaces with prefixes"
expecteof "$clixon_netconf -qf $cfg" 0 ' \t \ foo\n ]]>]]>' '^]]>]]>$'
new "get stripped whitespace"
expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^foo]]>]]>$'
new "validate"
expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$"
new "netconf discard-changes"
expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$"
new "add insignificant 'clean' whitespaces"
expecteof "$clixon_netconf -qf $cfg" 0 ' \n \t ]]>]]>' '^]]>]]>$'
new "add more insignificant 'clean' whitespaces"
expecteof "$clixon_netconf -qf $cfg" 0 'foo ]]>]]>' '^]]>]]>$'
new "get stripped whitespace"
expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^foo]]>]]>'
new "validate"
expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$"
new "netconf discard-changes"
expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$"
new "add significant whitespaces"
expecteof "$clixon_netconf -qf $cfg" 0 ' foo
bar ]]>]]>' '^]]>]]>$'
new "get significant whitespace"
expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' '^ foo
bar ]]>]]>'
new "validate"
expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$"
new "netconf discard-changes"
expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$"
if [ $BE -eq 0 ]; then
exit # BE
fi
new "Kill backend"
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
if [ -z "$pid" ]; then
err "backend already dead"
fi
# kill backend
stop_backend -f $cfg
rm -rf $dir