From c27ecf0923709cb64ad82a02edbd8b7397138509 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 10 May 2022 17:37:55 +0200 Subject: [PATCH] Test: added test of CLI rest variables with delimiters --- test/test_cli_rest.sh | 112 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100755 test/test_cli_rest.sh diff --git a/test/test_cli_rest.sh b/test/test_cli_rest.sh new file mode 100755 index 00000000..f375f569 --- /dev/null +++ b/test/test_cli_rest.sh @@ -0,0 +1,112 @@ +#!/usr/bin/env bash +# CLIgen rest and delimiters test +# Special code for and if the value has delimiters, such as "a b" + +# 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 + +# include err() and new() functions and creates $dir + +cfg=$dir/conf_yang.xml +fyang=$dir/clixon-example.yang +clidir=$dir/clidir + +if [ ! -d $clidir ]; then + mkdir $clidir +fi + +cat < $cfg + + $cfg + ${YANG_INSTALLDIR} + $fyang + /usr/local/lib/$APPNAME/backend + $clidir + /usr/local/lib/$APPNAME/cli + $APPNAME + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + /usr/local/var/$APPNAME + +EOF + +cat < $fyang +module clixon-example{ + yang-version 1.1; + namespace "urn:example:clixon"; + prefix ex; + leaf description{ + type string; + } +} +EOF + +# clispec files 1..6 for submodes AAA and BBB as described in top comment + +cat < $clidir/cli1.cli + CLICON_MODE="example"; + description + ( + | ), + cli_set("/clixon-example:description"); + show configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "xml", false, false); +EOF + +new "test params: -f $cfg" +if [ $BE -ne 0 ]; then + new "kill old backend" + sudo clixon_backend -z -f $cfg + if [ $? -ne 0 ]; then + err + fi + new "start backend -s init -f $cfg" + start_backend -s init -f $cfg +fi + +new "wait backend" +wait_backend + +new "Add a b" +expectpart "$($clixon_cli -1 -f $cfg description a b)" 0 "^$" + +new "Add a b c" +expectpart "$($clixon_cli -1 -f $cfg description a b c)" 0 "^$" + +new "Show config" +expectpart "$($clixon_cli -1 -f $cfg show config)" 0 "^a b c$" + +new "Re-add a b c" +expectpart "$($clixon_cli -1 -f $cfg description a b c)" 0 "^$" + +new "Show config again" +expectpart "$($clixon_cli -1 -f $cfg show config)" 0 "^a b c$" + +new "Expand " +expectpart "$(echo "description " | $clixon_cli -f $cfg 2>&1)" 0 "description a b c" + +new "Expand a " +expectpart "$(echo "description a " | $clixon_cli -f $cfg 2>&1)" 0 "description a b c" + +new "Show config again" +expectpart "$($clixon_cli -1 -f $cfg show config)" 0 "^a b c$" + +new "Add a b" +expectpart "$($clixon_cli -1 -f $cfg description a b)" 0 "^$" + +if [ $BE -ne 0 ]; then + 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 +fi + +rm -rf $dir + +new "endtest" +endtest