mirror of
https://github.com/pi-hole/docker-pi-hole.git
synced 2026-04-24 02:39:27 +01:00
Container creation, waiting, and teardown previously lived in run.sh and were passed to test_suite.bats via exported environment variables. This scattered container lifecycle between two files and required custom inline logic for tests that needed their own container. Replace test_suite.bats with two focused files, each owning their container via setup_file/teardown_file: - test_default.bats: plain container; covers FTL binary, cron, password generation, and graceful shutdown (run last, sequentially) - test_env_vars.bats: custom UID/GID, FTLCONF_ vars, ADDITIONAL_PACKAGES, and TAIL_FTL_LOG=0 all exercised in a single container Extract start_container and wait_for_log into test/helpers.sh, which each .bats file loads directly. run.sh now only builds the image, installs BATS, and invokes the test files. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Adam Warner <me@adamwarner.co.uk>
62 lines
1.8 KiB
Bash
62 lines
1.8 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load 'libs/bats-support/load'
|
|
load 'libs/bats-assert/load'
|
|
load 'helpers.sh'
|
|
|
|
setup_file() {
|
|
CONTAINER=$(start_container)
|
|
wait_for_log "$CONTAINER" "########## FTL started"
|
|
export CONTAINER
|
|
# Force tests in this file to run sequentially since the shutdown test will destroy the container that other tests depend on
|
|
export BATS_NO_PARALLELIZE_WITHIN_FILE=true
|
|
}
|
|
|
|
teardown_file() {
|
|
docker rm -f "$CONTAINER" > /dev/null 2>&1 || true
|
|
}
|
|
|
|
# ---- FTL binary -------------------------------------------------------------
|
|
|
|
@test "FTL reports version" {
|
|
run docker exec "$CONTAINER" pihole-FTL -vv
|
|
assert_success
|
|
assert_output --partial "Version:"
|
|
}
|
|
|
|
@test "FTL reports correct architecture" {
|
|
[ -n "${CIPLATFORM:-}" ] || skip "CIPLATFORM not set, running locally"
|
|
run docker exec "$CONTAINER" pihole-FTL -vv
|
|
assert_success
|
|
assert_output --partial "Architecture:"
|
|
assert_output --partial "$CIPLATFORM"
|
|
}
|
|
|
|
# ---- Container configuration ------------------------------------------------
|
|
|
|
@test "Cron file is valid" {
|
|
run docker exec "$CONTAINER" /usr/bin/crontab /crontab.txt
|
|
assert_success
|
|
}
|
|
|
|
# ---- Web password setup -----------------------------------------------------
|
|
|
|
@test "Random password is assigned on fresh start" {
|
|
run docker logs "$CONTAINER"
|
|
assert_success
|
|
assert_output --partial "assigning random password:"
|
|
}
|
|
|
|
# ---- FTL shutdown (DO THIS LAST!)---------------------------------------------
|
|
|
|
@test "FTL starts up and shuts down cleanly" {
|
|
# Stop gracefully (SIGTERM), then capture logs before teardown_file removes it
|
|
run docker stop "$CONTAINER"
|
|
local logs
|
|
logs=$(docker logs "$CONTAINER" 2>&1)
|
|
|
|
run echo "$logs"
|
|
assert_output --partial "INFO: ########## FTL terminated after"
|
|
assert_output --partial "(code 0)"
|
|
}
|