mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-25 07:41:10 +00:00
165 lines
5.2 KiB
Bash
Executable File
165 lines
5.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Tests for Serval DNA configuration operations.
|
|
#
|
|
# Copyright 2012 Paul Gardner-Stephen
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; either version 2
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
source "${0%/*}/../testframework.sh"
|
|
source "${0%/*}/../testdefs.sh"
|
|
|
|
setup() {
|
|
setup_servald
|
|
}
|
|
|
|
doc_GetCreateInstanceDir="Get creates instance directory"
|
|
setup_GetCreateInstanceDir() {
|
|
setup_servald --no-mkdir
|
|
assert [ ! -d $SERVALINSTANCE_PATH ]
|
|
}
|
|
test_GetCreateInstanceDir() {
|
|
executeOk $servald config get
|
|
assert [ -d $SERVALINSTANCE_PATH ]
|
|
}
|
|
|
|
doc_SetCreateInstanceDir="Set creates instance directory"
|
|
setup_SetCreateInstanceDir() {
|
|
setup_servald --no-mkdir
|
|
assert [ ! -d $SERVALINSTANCE_PATH ]
|
|
}
|
|
test_SetCreateInstanceDir() {
|
|
executeOk $servald config set foo bar
|
|
assert [ -d $SERVALINSTANCE_PATH ]
|
|
}
|
|
|
|
doc_GetNull="Get an unset config item"
|
|
test_GetNull() {
|
|
executeOk $servald config get foo
|
|
assertStdoutLineCount '==' 0
|
|
}
|
|
|
|
doc_SetGet="Set and get a single config item"
|
|
test_SetGet() {
|
|
executeOk $servald config set foo bar
|
|
executeOk $servald config get foo
|
|
assertStdoutLineCount '==' 1
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo=bar$'
|
|
}
|
|
|
|
doc_GetAll="Get all config items"
|
|
test_GetAll() {
|
|
executeOk $servald config set foo bar
|
|
executeOk $servald config set hello world
|
|
executeOk $servald config get
|
|
assertStdoutLineCount '==' 2
|
|
assertStdoutGrep --stdout --matches=1 '^foo=bar$'
|
|
assertStdoutGrep --stdout --matches=1 '^hello=world$'
|
|
}
|
|
|
|
doc_SetTwice="Set a single config item twice"
|
|
test_SetTwice() {
|
|
executeOk $servald config set foo bar
|
|
executeOk $servald config get foo
|
|
assertStdoutLineCount '==' 1
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo=bar$'
|
|
executeOk $servald config set foo wah
|
|
executeOk $servald config get foo
|
|
assertStdoutLineCount '==' 1
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo=wah$'
|
|
}
|
|
|
|
doc_DelNull="Delete an unset config item"
|
|
test_DelNull() {
|
|
executeOk $servald config del foo
|
|
assertStdoutLineCount '==' 0
|
|
}
|
|
|
|
doc_Del="Delete single config item"
|
|
test_Del() {
|
|
executeOk $servald config set foo bar
|
|
executeOk $servald config set hello world
|
|
executeOk $servald config get
|
|
assertStdoutLineCount '==' 2
|
|
executeOk $servald config del foo
|
|
executeOk $servald config get
|
|
assertStdoutLineCount '==' 1
|
|
executeOk $servald config get foo
|
|
assertStdoutLineCount '==' 0
|
|
}
|
|
|
|
doc_CaseInsensitive="Config item names are case insensitive"
|
|
test_CaseInsensitive() {
|
|
executeOk $servald config set foo bar
|
|
executeOk $servald config get foo
|
|
assertStdoutLineCount '==' 1
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo=bar$'
|
|
executeOk $servald config get Foo
|
|
assertStdoutLineCount '==' 1
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo=bar$'
|
|
executeOk $servald config set FOO wah
|
|
executeOk $servald config get foo
|
|
assertStdoutLineCount '==' 1
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^FOO=wah$'
|
|
}
|
|
|
|
doc_DotsInNames="Config item names can have internal dots"
|
|
test_DotsInNames() {
|
|
executeOk $servald config set foo.bar yes
|
|
executeOk $servald config get foo.bar
|
|
assertStdoutLineCount '==' 1
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo\.bar=yes$'
|
|
execute $servald config set foo. yes
|
|
assertExitStatus '!=' 0
|
|
execute $servald config set .foo yes
|
|
assertExitStatus '!=' 0
|
|
execute $servald config set foo..bar yes
|
|
assertExitStatus '!=' 0
|
|
executeOk $servald config set foo.x.bar yes
|
|
executeOk $servald config get foo.x.bar
|
|
assertStdoutLineCount '==' 1
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo\.x\.bar=yes$'
|
|
}
|
|
|
|
doc_DebugFlags="Debug config options affect verbosity"
|
|
test_DebugFlags() {
|
|
executeOk $servald echo one two three
|
|
assertStderrGrep --matches=0 '\<echo:argv\['
|
|
executeOk $servald config set debug.verbose true
|
|
executeOk $servald echo one two three
|
|
assertStderrGrep --matches=3 '\<echo:argv\['
|
|
executeOk $servald config set debug.verbose false
|
|
executeOk $servald echo one two three
|
|
assertStderrGrep --matches=0 '\<echo:argv\['
|
|
}
|
|
|
|
doc_DebugFlagAll="Debug config options override debug.all"
|
|
test_DebugFlagAll() {
|
|
executeOk $servald config set debug.all yes
|
|
executeOk $servald echo one two three
|
|
assertStderrGrep --matches=3 '\<echo:argv\['
|
|
executeOk $servald config set debug.verbose false
|
|
executeOk $servald echo one two three
|
|
assertStderrGrep --matches=0 '\<echo:argv\['
|
|
executeOk $servald config set debug.verbose true
|
|
executeOk $servald echo one two three
|
|
assertStderrGrep --matches=3 '\<echo:argv\['
|
|
executeOk $servald config set debug.all off
|
|
executeOk $servald echo one two three
|
|
assertStderrGrep --matches=3 '\<echo:argv\['
|
|
}
|
|
|
|
runTests "$@"
|