test: Add two new tests

* test_start_stop_service

  Test that we can start/stop (via initctl) a service configured in
  finit.conf

* test_start_stop_service_sub_config

  Test that we can start/stop (via initctl) a service configured in
  finit.d/ files

Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
This commit is contained in:
Magnus Malm
2021-02-23 15:30:42 +01:00
parent 51fe6a15e9
commit 25ffc3192f
3 changed files with 83 additions and 0 deletions
+2
View File
@@ -2,6 +2,8 @@ AM_TESTS_ENVIRONMENT = make -C test_root/;
TESTS = checkself.sh
TESTS += test_add_remove_dynamic_service/test.sh
TESTS += test_add_remove_dynamic_service_sub_config/test.sh
TESTS += test_start_stop_service/test.sh
TESTS += test_start_stop_service_sub_config/test.sh
clean-local:
make -C test_root/ clean
+40
View File
@@ -0,0 +1,40 @@
#!/bin/sh
set -eu
TEST_DIR=$(dirname "$0")/..
# shellcheck source=/dev/null
. "$TEST_DIR/lib.sh"
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 "Test start $(date)"
say 'Add service stanza in /etc/finit.conf'
cp "$TEST_DIR"/common/service.sh "$TEST_DIR"/test_root/test_assets/
texec sh -c "echo 'service [2345] kill:20 log /test_assets/service.sh' > $FINIT_CONF"
say 'Reload Finit'
texec sh -c "initctl reload"
retry 'assert_num_children 1 service.sh'
say 'Stop the service'
texec sh -c "initctl stop service.sh"
retry 'assert_num_children 0 service.sh'
say 'Start the service again'
texec sh -c "initctl start service.sh"
retry 'assert_num_children 1 service.sh'
+41
View File
@@ -0,0 +1,41 @@
#!/bin/sh
set -eu
TEST_DIR=$(dirname "$0")/..
# shellcheck source=/dev/null
. "$TEST_DIR/lib.sh"
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 "Test start $(date)"
say 'Add service stanza in /etc/finit.d/service.conf'
cp "$TEST_DIR"/common/service.sh "$TEST_DIR"/test_root/test_assets/
# texec sh -c "echo 'service [2345] kill:20 log /test_assets/service.sh' > $FINIT_CONF"
texec sh -c "echo 'service [2345] kill:20 log /test_assets/service.sh' > $FINIT_CONF_DIR/service.conf"
say 'Reload Finit'
texec sh -c "initctl reload"
retry 'assert_num_children 1 service.sh'
say 'Stop the service'
texec sh -c "initctl stop service.sh"
retry 'assert_num_children 0 service.sh'
say 'Start the service again'
texec sh -c "initctl start service.sh"
retry 'assert_num_children 1 service.sh'