2012-04-12 08:06:27 +00:00
|
|
|
#!/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() {
|
2012-05-20 04:18:02 +00:00
|
|
|
setup_servald
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_GetCreateInstanceDir="Get creates instance directory"
|
|
|
|
setup_GetCreateInstanceDir() {
|
2012-06-04 08:58:05 +00:00
|
|
|
setup
|
|
|
|
assert [ ! -d "$SERVALINSTANCE_PATH" ]
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
test_GetCreateInstanceDir() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config get
|
2012-06-04 08:58:05 +00:00
|
|
|
assert [ -d "$SERVALINSTANCE_PATH" ]
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_SetCreateInstanceDir="Set creates instance directory"
|
|
|
|
setup_SetCreateInstanceDir() {
|
2012-06-04 08:58:05 +00:00
|
|
|
setup
|
|
|
|
assert [ ! -d "$SERVALINSTANCE_PATH" ]
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
test_SetCreateInstanceDir() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set foo bar
|
2012-06-04 08:58:05 +00:00
|
|
|
assert [ -d "$SERVALINSTANCE_PATH" ]
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_GetNull="Get an unset config item"
|
|
|
|
test_GetNull() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config get foo
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 0
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_SetGet="Set and get a single config item"
|
|
|
|
test_SetGet() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set foo bar
|
|
|
|
executeOk_servald config get foo
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
|
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo=bar$'
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_GetAll="Get all config items"
|
|
|
|
test_GetAll() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set foo bar
|
|
|
|
executeOk_servald config set hello world
|
|
|
|
executeOk_servald config get
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 2
|
|
|
|
assertStdoutGrep --stdout --matches=1 '^foo=bar$'
|
|
|
|
assertStdoutGrep --stdout --matches=1 '^hello=world$'
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_SetTwice="Set a single config item twice"
|
|
|
|
test_SetTwice() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set foo bar
|
|
|
|
executeOk_servald config get foo
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
|
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo=bar$'
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set foo wah
|
|
|
|
executeOk_servald config get foo
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
|
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo=wah$'
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_DelNull="Delete an unset config item"
|
|
|
|
test_DelNull() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config del foo
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 0
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_Del="Delete single config item"
|
|
|
|
test_Del() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set foo bar
|
|
|
|
executeOk_servald config set hello world
|
|
|
|
executeOk_servald config get
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 2
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config del foo
|
|
|
|
executeOk_servald config get
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config get foo
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 0
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_CaseInsensitive="Config item names are case insensitive"
|
|
|
|
test_CaseInsensitive() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set foo bar
|
|
|
|
executeOk_servald config get foo
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
|
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo=bar$'
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config get Foo
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
2012-07-05 05:29:50 +00:00
|
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^Foo=bar$'
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set FOO wah
|
|
|
|
executeOk_servald config get foo
|
2012-04-12 08:06:27 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
2012-07-05 05:29:50 +00:00
|
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo=wah$'
|
2012-04-12 08:06:27 +00:00
|
|
|
}
|
|
|
|
|
2012-05-14 09:02:10 +00:00
|
|
|
doc_DotsInNames="Config item names can have internal dots"
|
|
|
|
test_DotsInNames() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set foo.bar yes
|
|
|
|
executeOk_servald config get foo.bar
|
2012-05-14 09:02:10 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
|
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo\.bar=yes$'
|
2012-05-20 04:18:02 +00:00
|
|
|
execute $servald config set foo. yes
|
2012-05-14 09:02:10 +00:00
|
|
|
assertExitStatus '!=' 0
|
2012-05-20 04:18:02 +00:00
|
|
|
execute $servald config set .foo yes
|
2012-05-14 09:02:10 +00:00
|
|
|
assertExitStatus '!=' 0
|
2012-05-20 04:18:02 +00:00
|
|
|
execute $servald config set foo..bar yes
|
2012-05-14 09:02:10 +00:00
|
|
|
assertExitStatus '!=' 0
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set foo.x.bar yes
|
|
|
|
executeOk_servald config get foo.x.bar
|
2012-05-14 09:02:10 +00:00
|
|
|
assertStdoutLineCount '==' 1
|
|
|
|
assertStdoutGrep --stdout --stderr --matches=1 '^foo\.x\.bar=yes$'
|
|
|
|
}
|
|
|
|
|
2012-05-15 00:19:40 +00:00
|
|
|
doc_DebugFlags="Debug config options affect verbosity"
|
2012-05-14 09:02:10 +00:00
|
|
|
test_DebugFlags() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald echo one two three
|
2012-05-14 09:02:10 +00:00
|
|
|
assertStderrGrep --matches=0 '\<echo:argv\['
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set debug.verbose true
|
|
|
|
executeOk_servald echo one two three
|
2012-05-14 09:02:10 +00:00
|
|
|
assertStderrGrep --matches=3 '\<echo:argv\['
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set debug.verbose false
|
|
|
|
executeOk_servald echo one two three
|
2012-05-14 09:02:10 +00:00
|
|
|
assertStderrGrep --matches=0 '\<echo:argv\['
|
|
|
|
}
|
|
|
|
|
2012-05-15 00:19:40 +00:00
|
|
|
doc_DebugFlagAll="Debug config options override debug.all"
|
|
|
|
test_DebugFlagAll() {
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set debug.all yes
|
|
|
|
executeOk_servald echo one two three
|
2012-05-15 00:19:40 +00:00
|
|
|
assertStderrGrep --matches=3 '\<echo:argv\['
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set debug.verbose false
|
|
|
|
executeOk_servald echo one two three
|
2012-05-15 00:19:40 +00:00
|
|
|
assertStderrGrep --matches=0 '\<echo:argv\['
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set debug.verbose true
|
|
|
|
executeOk_servald echo one two three
|
2012-05-15 00:19:40 +00:00
|
|
|
assertStderrGrep --matches=3 '\<echo:argv\['
|
2012-06-08 03:43:26 +00:00
|
|
|
executeOk_servald config set debug.all off
|
|
|
|
executeOk_servald echo one two three
|
2012-05-15 00:19:40 +00:00
|
|
|
assertStderrGrep --matches=3 '\<echo:argv\['
|
|
|
|
}
|
|
|
|
|
2012-04-12 08:06:27 +00:00
|
|
|
runTests "$@"
|