Skip to content

Commit

Permalink
test: verify pre:/post:scripts also for configlets
Browse files Browse the repository at this point in the history
For a background, see issue #399

Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Mar 23, 2024
1 parent cab94b8 commit eb4eca9
Showing 1 changed file with 61 additions and 12 deletions.
73 changes: 61 additions & 12 deletions test/pre-post-serv.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/sh
#
# Verify pre:script and post:script runs as intended when starting,
# stopping and disabling services in various configurations and
# conditions.
#

set -eu

TEST_DIR=$(dirname "$0")
Expand All @@ -16,40 +22,83 @@ test_teardown()
run "rm -f $FINIT_CONF"
}

test_one()
startit()
{
pre=$1
precont=$2
service=$3
post=$4
postcont=$5
service=$1
conf=$2
pre=$3
precont=$4

say "Add service stanza '$service' to $FINIT_CONF ..."
run "echo '$service' > $FINIT_CONF"
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

say 'Stop the service'
run "initctl stop serv"
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 service from $FINIT_CONF ..."
run "rm $FINIT_CONF"
say "Done, drop $conf ..."
run "rm $conf"
run "initctl reload"
}

test_one()
{
pre=$1
precont=$2
service=$3
post=$4
postcont=$5
avail="$FINIT_RCSD/available/serv.conf"

sep "Stage 1/2"
startit "$service" "$FINIT_CONF" "$pre" "$precont"
stopit "$FINIT_CONF" "$post" "$postcont"

sep "Stage 2/2"
startit "$service" "$avail" "$pre" "$precont"
stopit "$avail" "$post" "$postcont"
}

# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"

Expand Down

0 comments on commit eb4eca9

Please sign in to comment.