ctdb-tests: Add test cleanup hooks
authorAmitay Isaacs <amitay@gmail.com>
Mon, 6 Jul 2015 05:14:53 +0000 (15:14 +1000)
committerMartin Schwenke <martins@samba.org>
Thu, 9 Jul 2015 04:23:21 +0000 (06:23 +0200)
To do any cleanup before exiting the test, register hooks with
test_cleanup().  Multiple hooks can be registered.  All the hooks will
be called before exiting from the test.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/tests/onnode/scripts/local.sh
ctdb/tests/scripts/unit.sh

index daefaa4720187a93d42dda6caaab63b6bfd02827..b9f4f0ada4ec5701a5e25d2e334447ea8f94363f 100644 (file)
@@ -46,7 +46,7 @@ ctdb_set_output ()
     _rc="$ONNODE_TESTS_VAR_DIR/ctdb.rc"
     echo "${1:-0}" >"$_rc"
 
-    trap "rm -f $_out $_rc" 0
+    test_cleanup "rm -f $_out $_rc"
 }
 
 extra_footer ()
index e9a04e1433f128d8d3c0daffc7b189409525a096..f52ef2c7efe6fe840f06878e6abaa139beb388bb 100644 (file)
@@ -209,6 +209,15 @@ script_test ()
     result_check || exit $?
 }
 
+test_cleanup_hooks=""
+
+test_cleanup ()
+{
+    test_cleanup_hooks="${test_cleanup_hooks}${test_cleanup_hooks:+ ; }$*"
+}
+
+trap 'eval $test_cleanup_hooks' 0
+
 local="${TEST_SUBDIR}/scripts/local.sh"
 if [ -r "$local" ] ; then
     . "$local"