mirror of
https://github.com/troglobit/finit.git
synced 2026-11-02 13:20:32 +00:00
test: verify pre:/post:scripts also for configlets
For a background, see issue #399 Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
cab94b81e8
commit
eb4eca9607
1 file changed
+72
-23
+72
-23
@@ -1,4 +1,10 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Verify pre:script and post:script runs as intended when starting,
|
||||||
|
# stopping and disabling services in various configurations and
|
||||||
|
# conditions.
|
||||||
|
#
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
TEST_DIR=$(dirname "$0")
|
TEST_DIR=$(dirname "$0")
|
||||||
@@ -16,6 +22,65 @@ test_teardown()
|
|||||||
run "rm -f $FINIT_CONF"
|
run "rm -f $FINIT_CONF"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startit()
|
||||||
|
{
|
||||||
|
service=$1
|
||||||
|
conf=$2
|
||||||
|
pre=$3
|
||||||
|
precont=$4
|
||||||
|
|
||||||
|
say "Add stanza '$service' to $conf ..."
|
||||||
|
run "echo '$service' > $conf"
|
||||||
|
|
||||||
|
if echo "$conf" |grep -q available; then
|
||||||
|
# configlets need must be enabled
|
||||||
|
run "initctl enable serv"
|
||||||
|
fi
|
||||||
|
|
||||||
|
say 'Reload Finit'
|
||||||
|
run "initctl reload"
|
||||||
|
|
||||||
|
# Ensure service has started before checking pre condition
|
||||||
|
retry 'assert_num_children 1 serv'
|
||||||
|
|
||||||
|
# Verify pre:script has run
|
||||||
|
if [ -n "$pre" ]; then
|
||||||
|
assert_file_contains "$pre" "$precont"
|
||||||
|
# Drop pre condition indicator for next test
|
||||||
|
run "rm -f $pre"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
stopit()
|
||||||
|
{
|
||||||
|
conf=$1
|
||||||
|
post=$2
|
||||||
|
postcont=$3
|
||||||
|
|
||||||
|
if echo "$conf" |grep -q available; then
|
||||||
|
say 'Disable service & reload'
|
||||||
|
run "initctl disable serv"
|
||||||
|
run "initctl reload"
|
||||||
|
else
|
||||||
|
say 'Stop the service'
|
||||||
|
run "initctl stop serv"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure service has stopped before checking for post condition
|
||||||
|
retry 'assert_num_children 0 serv'
|
||||||
|
|
||||||
|
# Verify post:script has run
|
||||||
|
if [ -n "$post" ]; then
|
||||||
|
assert_file_contains "$post" "$postcont"
|
||||||
|
# Drop post condition indicator for next test
|
||||||
|
run "rm -f $post"
|
||||||
|
fi
|
||||||
|
|
||||||
|
say "Done, drop $conf ..."
|
||||||
|
run "rm $conf"
|
||||||
|
run "initctl reload"
|
||||||
|
}
|
||||||
|
|
||||||
test_one()
|
test_one()
|
||||||
{
|
{
|
||||||
pre=$1
|
pre=$1
|
||||||
@@ -23,31 +88,15 @@ test_one()
|
|||||||
service=$3
|
service=$3
|
||||||
post=$4
|
post=$4
|
||||||
postcont=$5
|
postcont=$5
|
||||||
|
avail="$FINIT_RCSD/available/serv.conf"
|
||||||
|
|
||||||
say "Add service stanza '$service' to $FINIT_CONF ..."
|
sep "Stage 1/2"
|
||||||
run "echo '$service' > $FINIT_CONF"
|
startit "$service" "$FINIT_CONF" "$pre" "$precont"
|
||||||
|
stopit "$FINIT_CONF" "$post" "$postcont"
|
||||||
|
|
||||||
say 'Reload Finit'
|
sep "Stage 2/2"
|
||||||
run "initctl reload"
|
startit "$service" "$avail" "$pre" "$precont"
|
||||||
|
stopit "$avail" "$post" "$postcont"
|
||||||
retry 'assert_num_children 1 serv'
|
|
||||||
if [ -n "$pre" ]; then
|
|
||||||
assert_file_contains "$pre" "$precont"
|
|
||||||
run "rm -f $pre"
|
|
||||||
fi
|
|
||||||
|
|
||||||
say 'Stop the service'
|
|
||||||
run "initctl stop serv"
|
|
||||||
|
|
||||||
retry 'assert_num_children 0 serv'
|
|
||||||
if [ -n "$post" ]; then
|
|
||||||
assert_file_contains "$post" "$postcont"
|
|
||||||
run "rm -f $post"
|
|
||||||
fi
|
|
||||||
|
|
||||||
say "Done, drop service from $FINIT_CONF ..."
|
|
||||||
run "rm $FINIT_CONF"
|
|
||||||
run "initctl reload"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
|
|||||||
Reference in new issue
Block a user