diff --git a/test/Makefile.am b/test/Makefile.am index 82740a98..8c9c4d27 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -23,6 +23,7 @@ EXTRA_DIST += add-remove-dynamic-service-sub-config.sh EXTRA_DIST += cond-start-task.sh EXTRA_DIST += failing-sysv.sh EXTRA_DIST += global-envs.sh +EXTRA_DIST += initctl-status-subset.sh EXTRA_DIST += pre-post-serv.sh EXTRA_DIST += restart-self.sh EXTRA_DIST += runlevel.sh @@ -52,6 +53,7 @@ TESTS += add-remove-dynamic-service-sub-config.sh TESTS += cond-start-task.sh TESTS += failing-sysv.sh TESTS += global-envs.sh +TESTS += initctl-status-subset.sh TESTS += pre-post-serv.sh TESTS += restart-self.sh TESTS += runlevel.sh diff --git a/test/initctl-status-subset.sh b/test/initctl-status-subset.sh new file mode 100755 index 00000000..c7019cc2 --- /dev/null +++ b/test/initctl-status-subset.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# Verify that the status command 'initctl status foo' matches three +# instances of tasks called foo:1, foo:2, and foo:3. It should not +# match the fourth task called foobar. This is a regression test to +# ensure issue #275 doesn't happen again. +set -eu + +TEST_DIR=$(dirname "$0") + +test_setup() +{ + say "Test start $(date)" +} + +test_teardown() +{ + say "Test done $(date)" + + texec rm -f "$FINIT_CONF" +} + +test_init() +{ + texec sh -c "echo '# Three foo and one bar enter Finit' > $FINIT_CONF" +} + +test_add_one() +{ + service=$1 + + say "Add service stanza '$service' to $FINIT_CONF ..." + texec sh -c "echo '$service' >> $FINIT_CONF" +} + +# shellcheck source=/dev/null +. "$TEST_DIR/tenv/lib.sh" + +test_init + +test_add_one "task manual:yes name:foo :1 serv -- Foo #1" +test_add_one "task manual:yes name:foo :2 serv -- Foo #2" +test_add_one "task manual:yes name:foo :3 serv -- Foo #3" +test_add_one "task manual:yes name:foobar serv -- Foobar" + +say 'Reload Finit' +#texec sh -c "initctl debug" +texec sh -c "initctl reload" +texec sh -c "initctl status" + +#texec sh -c "initctl status" +#texec sh -c "ps" +#texec sh -c "initctl status serv" + +assert_num_services 3 foo +assert_desc "Foobar" foobar +assert_desc "Foo #1" foo:1 + diff --git a/test/tenv/lib.sh b/test/tenv/lib.sh index 27047d01..cf21f165 100755 --- a/test/tenv/lib.sh +++ b/test/tenv/lib.sh @@ -31,6 +31,11 @@ assert_num_children() assert "$1 services are running" "$(texec pgrep -P 1 "$2" | wc -l)" -eq "$1" } +assert_num_services() +{ + assert "$1 services are loaded" "$(texec initctl -t status "$2" | wc -l)" -eq "$1" +} + # shellcheck disable=SC2086 assert_new_pid() { @@ -42,6 +47,11 @@ assert_restarts() assert "Finit has registered restarts" "$(texec initctl status "$2" | awk '/Restarts/{print $3;}')" -ge "$1" } +assert_desc() +{ + assert "Service description == $1" "$(texec initctl status "$2" | grep 'Description' | sed 's/Description : //')" = "$1" +} + # shellcheck disable=SC2086 assert_pidfile() {