Skip to content

Commit 9fc8cd3

Browse files
PromoFauxclaude
andcommitted
test: expand Docker container test coverage
Add tests for areas of container behaviour not previously exercised: - crond is running (not just that the crontab file is valid) - Logrotate config is installed at /etc/pihole/logrotate - Default DNS upstreams (8.8.8.8/8.8.4.4) applied when none configured - Web interface accessible at /admin/ (default port and custom port) - /pihole.docker.tag build metadata file is present - macvendor.db is present and configured in FTL - FTL is running as the pihole user (validates DNSMASQ_USER default) - Capabilities are applied to pihole-FTL (validates fix_capabilities) - WEBPASSWORD_FILE reads the web password from a Docker secret Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Adam Warner <me@adamwarner.co.uk>
1 parent acd1cf7 commit 9fc8cd3

4 files changed

Lines changed: 99 additions & 0 deletions

File tree

test/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export CIPLATFORM
4343
TEST_FILES=(
4444
test_default.bats
4545
test_env_vars.bats
46+
test_secrets.bats
4647
)
4748

4849
# Configure BATS output and parallelization

test/test_default.bats

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,65 @@ teardown_file() {
4747
assert_output --partial "assigning random password:"
4848
}
4949

50+
# ---- Container services -----------------------------------------------------
51+
52+
@test "crond is running" {
53+
run docker exec "$CONTAINER" pgrep crond
54+
assert_success
55+
}
56+
57+
@test "Logrotate config is installed" {
58+
run docker exec "$CONTAINER" test -f /etc/pihole/logrotate
59+
assert_success
60+
}
61+
62+
# ---- Default configuration --------------------------------------------------
63+
64+
@test "Default DNS upstreams are applied when none are configured" {
65+
run docker exec "$CONTAINER" pihole-FTL --config -q dns.upstreams
66+
assert_success
67+
assert_output --partial "8.8.8.8"
68+
assert_output --partial "8.8.4.4"
69+
}
70+
71+
# ---- Web interface ----------------------------------------------------------
72+
73+
@test "Web interface is accessible" {
74+
run docker exec "$CONTAINER" curl -sf /dev/null http://localhost/admin/
75+
assert_success
76+
}
77+
78+
# ---- Docker image -----------------------------------------------------------
79+
80+
@test "/pihole.docker.tag is present" {
81+
run docker exec "$CONTAINER" test -f /pihole.docker.tag
82+
assert_success
83+
}
84+
85+
@test "macvendor.db is present" {
86+
run docker exec "$CONTAINER" test -f /macvendor.db
87+
assert_success
88+
}
89+
90+
@test "macvendor.db path is configured in FTL" {
91+
run docker exec "$CONTAINER" pihole-FTL --config -q files.macvendor
92+
assert_success
93+
assert_output "/macvendor.db"
94+
}
95+
96+
# ---- Runtime ----------------------------------------------------------------
97+
98+
@test "FTL is running as the pihole user" {
99+
run docker exec "$CONTAINER" pgrep -u pihole pihole-FTL
100+
assert_success
101+
}
102+
103+
@test "Capabilities are applied to pihole-FTL" {
104+
run docker exec "$CONTAINER" getcap /usr/bin/pihole-FTL
105+
assert_success
106+
assert_output --partial "cap_net_raw"
107+
}
108+
50109
# ---- FTL shutdown (DO THIS LAST!)---------------------------------------------
51110

52111
@test "FTL starts up and shuts down cleanly" {

test/test_env_vars.bats

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ teardown_file() {
5959
assert_success
6060
}
6161

62+
# ---- Web interface ----------------------------------------------------------
63+
64+
@test "Web interface is accessible on custom port" {
65+
run docker exec "$CONTAINER" curl -sf http://localhost:8080/admin
66+
assert_success
67+
}
68+
6269
# ---- TAIL_FTL_LOG disabled --------------------------------------------------
6370

6471
@test "TAIL_FTL_LOG=0 suppresses FTL log output in docker logs" {

test/test_secrets.bats

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bats
2+
3+
load 'libs/bats-support/load'
4+
load 'libs/bats-assert/load'
5+
load 'helpers.sh'
6+
7+
setup_file() {
8+
# Create a temporary file to act as the Docker secret
9+
local secret_file
10+
secret_file=$(mktemp)
11+
echo -n "mysecretpassword" > "$secret_file"
12+
export SECRET_FILE="$secret_file"
13+
14+
CONTAINER=$(start_container \
15+
-e WEBPASSWORD_FILE=pihole_password \
16+
-v "${secret_file}:/run/secrets/pihole_password:ro")
17+
wait_for_log "$CONTAINER" "########## FTL started"
18+
export CONTAINER
19+
}
20+
21+
teardown_file() {
22+
docker rm -f "$CONTAINER" > /dev/null 2>&1 || true
23+
rm -f "$SECRET_FILE"
24+
}
25+
26+
# ---- Docker secrets ---------------------------------------------------------
27+
28+
@test "WEBPASSWORD_FILE reads the web password from a Docker secret" {
29+
run docker logs "$CONTAINER"
30+
assert_success
31+
assert_output --partial "Setting FTLCONF_webserver_api_password from file"
32+
}

0 commit comments

Comments
 (0)