summaryrefslogtreecommitdiff
path: root/ctdb/tests
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2015-12-14 21:08:03 +1100
committerAmitay Isaacs <amitay@samba.org>2016-01-25 07:18:25 +0100
commit3a2eebfe19e9c90271d68b17f588192c4d2f3d91 (patch)
tree4ee2b53772af2e86dbf39551d5b499ff58e6cccd /ctdb/tests
parent1538fc458568c9d5b29125256957f8d6de580d4c (diff)
downloadsamba-3a2eebfe19e9c90271d68b17f588192c4d2f3d91.tar.gz
ctdb-tests: Test ctdb CLI tool via a stub
Some features, such NAT gateway and LVS support, can be implemented without daemon and (internal) ctdb CLI tool support. These are non-core features that don't need incredible performance and they don't need to be in the core code. They can easily be reimplemented in scripts, along with some configuration changes. For continuity, the ctdb CLI tool code will call out to helper scripts so that the current status information can still be provided. Those helper scripts may then reinvoke the ctdb CLI tool to gather information. So, redo the tool testing using a "ctdb" stub command. This will swallow standard input and feed it to the test program each time the "ctdb" stub is called. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/tests')
-rw-r--r--ctdb/tests/tool/scripts/local.sh14
-rwxr-xr-xctdb/tests/tool/stubs/ctdb27
2 files changed, 38 insertions, 3 deletions
diff --git a/ctdb/tests/tool/scripts/local.sh b/ctdb/tests/tool/scripts/local.sh
index 737cb716278..68a25d2dad7 100644
--- a/ctdb/tests/tool/scripts/local.sh
+++ b/ctdb/tests/tool/scripts/local.sh
@@ -1,5 +1,11 @@
# Hey Emacs, this is a -*- shell-script -*- !!! :-)
+# Augment PATH with stubs/ directory.
+
+if [ -d "${TEST_SUBDIR}/stubs" ] ; then
+ PATH="${TEST_SUBDIR}/stubs:$PATH"
+fi
+
if "$TEST_VERBOSE" ; then
debug () { echo "$@" ; }
else
@@ -14,12 +20,14 @@ define_test ()
func.*)
_func="${_f#func.}"
_func="${_func%.*}" # Strip test number
- test_prog="ctdb_functest ${_func}"
+ export CTDB_TEST_PROG="ctdb_functest"
+ test_args="$_func"
;;
stubby.*)
_cmd="${_f#stubby.}"
_cmd="${_cmd%.*}" # Strip test number
- test_prog="ctdb_stubtest ${_cmd}"
+ export CTDB_TEST_PROG="ctdb_stubtest"
+ test_args="$_cmd"
;;
*)
die "Unknown pattern for testcase \"$_f\""
@@ -71,5 +79,5 @@ simple_test ()
: ${CTDB_DEBUGLEVEL:=3}
export CTDB_DEBUGLEVEL
- unit_test $test_prog "$@"
+ unit_test ctdb $test_args "$@"
}
diff --git a/ctdb/tests/tool/stubs/ctdb b/ctdb/tests/tool/stubs/ctdb
new file mode 100755
index 00000000000..c6e1e705c9a
--- /dev/null
+++ b/ctdb/tests/tool/stubs/ctdb
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# If "ctdb" is called several time in a test then it must always get
+# the same input. So, it is read here the first time and then fed to
+# all future instances.
+if [ -z "$_CTDB_TOOL_STUB_INPUT" ] ; then
+ if ! tty -s ; then
+ _CTDB_TOOL_STUB_INPUT=$(cat)
+ else
+ _CTDB_TOOL_STUB_INPUT=""
+ fi
+ # Let's not try being subtle about whether this variable is unset
+ # or empty. If we've been here then it is set, even if input was
+ # empty.
+ if [ -z "$_CTDB_TOOL_STUB_INPUT" ] ; then
+ _CTDB_TOOL_STUB_INPUT="@@@EMPTY@@@"
+ fi
+ export _CTDB_TOOL_STUB_INPUT
+fi
+
+if [ "$_CTDB_TOOL_STUB_INPUT" != "@@@EMPTY@@@" ] ; then
+ exec "$CTDB_TEST_PROG" "$@" <<EOF
+$_CTDB_TOOL_STUB_INPUT
+EOF
+else
+ exec "$CTDB_TEST_PROG" "$@" </dev/null
+fi