diff --git a/src/bash_functions.sh b/src/bash_functions.sh index 17eface..1911bea 100644 --- a/src/bash_functions.sh +++ b/src/bash_functions.sh @@ -52,9 +52,12 @@ ensure_basic_configuration() { # chown pihole:root "${PI_HOLE_BIN_DIR}/pihole" mkdir -p /etc/pihole - if [[ ! -f /etc/pihole/adlists.list ]]; then - echo "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" > /etc/pihole/adlists.list + if [[ -z "${PYTEST}" ]]; then + if [[ ! -f /etc/pihole/adlists.list ]]; then + echo "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" >/etc/pihole/adlists.list + fi fi + chown -R pihole:pihole /etc/pihole diff --git a/src/start.sh b/src/start.sh index 47c702f..1e293b0 100644 --- a/src/start.sh +++ b/src/start.sh @@ -147,6 +147,12 @@ stop() { sleep 0.5 done + # If we are running pytest, keep the container alive for a little longer + # to allow the tests to complete + if [[ ${PYTEST} ]]; then + sleep 10 + fi + exit } diff --git a/test/tests/test_general.py b/test/tests/test_general.py index 47d6e2a..a0f5398 100644 --- a/test/tests/test_general.py +++ b/test/tests/test_general.py @@ -11,3 +11,20 @@ def test_pihole_uid_env_var(docker): def test_pihole_gid_env_var(docker): func = docker.run("id -g pihole") assert "456" in func.stdout + + +# We immediately remove the adlists.list file so that gravity does not attempt to download a default list +# Wait 5 seconds for gravity to finish, then kill the start.sh script +# Finally, tail the FTL log to see if it shuts down cleanly +@pytest.mark.parametrize("test_args", ['-e "PH_VERBOSE=1"']) +def test_pihole_ftl_clean_shutdown(docker): + func = docker.run( + """ + sleep 5 + killall --signal 15 start.sh + sleep 5 + tail -f /var/log/pihole-FTL.log + """ + ) + assert "INFO: Shutting down... // exit code 0 // jmpret 0" in func.stdout + assert "INFO: ########## FTL terminated after" in func.stdout