#!/bin/bash # Tests for Serval DNA configuration operations. # # Copyright 2012 Serval Project, Inc. # # 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 } assert_stderr_log() { local -a warn_patterns=() local -a error_patterns=() while [ $# -gt 0 ]; do case "$1" in --warn-pattern=*) warn_patterns+=("${1#*=}"); shift;; --error-pattern=*) error_patterns+=("${1#*=}"); shift;; *) error "unsupported option: $1"; return;; esac done assertStderrGrep \ --matches=${#error_patterns[*]} \ --message="stderr of ($executed) contains exactly ${#error_patterns[*]} error message(s)" \ '^ERROR:' local pattern for pattern in "${warn_patterns[@]}"; do assertStderrGrep \ --message="stderr of ($executed) contains a warning message matching \"$pattern\"" \ "^WARN:.*$pattern" done for pattern in "${error_patterns[@]}"; do assertStderrGrep \ --message="stderr of ($executed) contains an error message matching \"$pattern\"" \ "^ERROR:.*$pattern" done } doc_GetCreateInstanceDir="Get creates instance directory" setup_GetCreateInstanceDir() { setup assert ! [ -d "$SERVALINSTANCE_PATH" ] } test_GetCreateInstanceDir() { executeOk_servald config get assert [ -d "$SERVALINSTANCE_PATH" ] } doc_SetCreateInstanceDir="Set creates instance directory" setup_SetCreateInstanceDir() { setup assert ! [ -d "$SERVALINSTANCE_PATH" ] } test_SetCreateInstanceDir() { executeOk_servald config set debug.verbose 0 assert [ -d "$SERVALINSTANCE_PATH" ] } doc_GetNull="Get an unset config item" test_GetNull() { executeOk_servald config get debug.verbose assertStdoutLineCount '==' 0 } doc_SetGet="Set and get a single config item" test_SetGet() { executeOk_servald config set debug.verbose yes executeOk_servald config get debug.verbose assertStdoutLineCount '==' 1 assertStdoutGrep --stdout --stderr --matches=1 '^debug\.verbose=yes$' } doc_GetAll="Get all config items" test_GetAll() { executeOk_servald config \ set debug.verbose true \ set log.show_pid true \ set server.chdir /tmp/nothing \ set rhizome.enable no executeOk_servald config get assertStdoutLineCount '==' 4 assertStdoutGrep --stdout --matches=1 '^debug\.verbose=true$' assertStdoutGrep --stdout --matches=1 '^log\.show_pid=true$' assertStdoutGrep --stdout --matches=1 '^server\.chdir=/tmp/nothing$' assertStdoutGrep --stdout --matches=1 '^rhizome\.enable=no$' } doc_SetDelMixed="Set and del config items in single command" test_SetDelMixed() { executeOk_servald config \ set debug.verbose true \ set log.show_pid true \ set server.chdir /tmp/nothing \ set rhizome.enable no executeOk_servald config \ set debug.verbose false \ del log.show_pid \ set log.show_time 1 \ del server.chdir \ del rhizome.enable executeOk_servald config get assertStdoutLineCount '==' 2 assertStdoutGrep --stdout --matches=1 '^debug\.verbose=false$' assertStdoutGrep --stdout --matches=1 '^log\.show_time=1$' } doc_SetTwice="Set a single config item twice" test_SetTwice() { executeOk_servald config set debug.verbose yes executeOk_servald config get debug.verbose assertStdoutLineCount '==' 1 assertStdoutGrep --stdout --stderr --matches=1 '^debug\.verbose=yes$' executeOk_servald config set debug.verbose false executeOk_servald config get debug.verbose assertStdoutLineCount '==' 1 assertStdoutGrep --stdout --stderr --matches=1 '^debug\.verbose=false$' } doc_DelNull="Delete an unset config item" test_DelNull() { executeOk_servald config del debug.verbose assertStdoutLineCount '==' 0 } doc_Del="Delete single config item" test_Del() { executeOk_servald config set debug.verbose yes set log.show_pid true executeOk_servald config get assertStdoutLineCount '==' 2 executeOk_servald config del debug.verbose executeOk_servald config get assertStdoutLineCount '==' 1 executeOk_servald config del log.show_pid assertStdoutLineCount '==' 0 } doc_CaseSensitive="Config item names are case sensitive" test_CaseSensitive() { execute $servald config set Debug.verbose yes assertExitStatus --stderr '!=' 0 } doc_OptionNames="Config item names must be well formed" test_OptionNames() { execute $servald config set debug. yes assertExitStatus --stderr '!=' 0 execute $servald config set .verbose yes assertExitStatus --stderr '!=' 0 execute $servald config del debug..verbose assertExitStatus --stderr '!=' 0 } doc_DebugFlags="Debug config options affect verbosity" test_DebugFlags() { executeOk_servald echo one two three assertStderrGrep --matches=0 '\