mirror of
https://github.com/troglobit/finit.git
synced 2026-10-12 10:12:32 +00:00
test: Add support for teardown in tests
If a test defines a function 'test_teardown(), that function will be called before the test env teardown is run. Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
This commit is contained in:
@@ -69,6 +69,11 @@ say() {
|
||||
|
||||
teardown() {
|
||||
test_status="$?"
|
||||
|
||||
if type test_teardown > /dev/null 2>&1 ; then
|
||||
test_teardown
|
||||
fi
|
||||
|
||||
log "$color_reset" '--' ''
|
||||
if [ "$test_status" -eq 0 ]; then
|
||||
log "$fg_green" 'TEST PASS' ''
|
||||
|
||||
@@ -10,6 +10,14 @@ assert_num_children() {
|
||||
assert "$1 services are running" "$(texec pgrep -P 1 "$2" | wc -l)" -eq "$1"
|
||||
}
|
||||
|
||||
test_teardown() {
|
||||
say "Test done $(date)"
|
||||
say "Running test teardown..."
|
||||
|
||||
# Teardown
|
||||
rm -f test_root/bin/service.sh
|
||||
}
|
||||
|
||||
# Test
|
||||
say 'Set up a service'
|
||||
cp "$TEST_DIR"/test_start_stop_service/service.sh "$TEST_DIR"/test_root/test_assets/
|
||||
@@ -27,6 +35,3 @@ say 'Reload Finit'
|
||||
texec kill -SIGHUP 1
|
||||
|
||||
retry 'assert_num_children 0 service.sh'
|
||||
|
||||
# Teardown
|
||||
rm -f test_root/bin/service.sh
|
||||
|
||||
Reference in New Issue
Block a user