From aa9ca809bebb17136e05817bc4c89c208424f52f Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Mon, 6 Jul 2015 15:14:53 +1000 Subject: ctdb-tests: Add test cleanup hooks 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 Reviewed-by: Martin Schwenke --- ctdb/tests/onnode/scripts/local.sh | 2 +- ctdb/tests/scripts/unit.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ctdb/tests/onnode/scripts/local.sh b/ctdb/tests/onnode/scripts/local.sh index daefaa47201..b9f4f0ada4e 100644 --- a/ctdb/tests/onnode/scripts/local.sh +++ b/ctdb/tests/onnode/scripts/local.sh @@ -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 () diff --git a/ctdb/tests/scripts/unit.sh b/ctdb/tests/scripts/unit.sh index e9a04e1433f..f52ef2c7efe 100644 --- a/ctdb/tests/scripts/unit.sh +++ b/ctdb/tests/scripts/unit.sh @@ -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" -- cgit v1.2.1