Files
docker-pi-hole/test/run.sh
Adam Warner 9fc8cd3229 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>
2026-03-30 22:24:44 +01:00

64 lines
1.8 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
# Run from the test/ directory regardless of where the script is called from
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# ---- Build the image --------------------------------------------------------
PLATFORM_ARGS=()
[ -n "${CIPLATFORM:-}" ] && PLATFORM_ARGS=(--platform "${CIPLATFORM}")
docker buildx build \
--load \
"${PLATFORM_ARGS[@]}" \
--progress plain \
-f ../src/Dockerfile \
-t pihole:test \
../src/
# ---- Install BATS -----------------------------------------------------------
if [ -z "${BATS:-}" ]; then
mkdir -p libs
if [ ! -d libs/bats ]; then
git clone --depth=1 --quiet --branch "${BATS_VERSION:-v1.13.0}" https://github.com/bats-core/bats-core libs/bats
fi
if [ ! -d libs/bats-support ]; then
git clone --depth=1 --quiet --branch "${BATS_SUPPORT_VERSION:-v0.3.0}" https://github.com/bats-core/bats-support libs/bats-support
fi
if [ ! -d libs/bats-assert ]; then
git clone --depth=1 --quiet --branch "${BATS_ASSERT_VERSION:-v2.2.4}" https://github.com/bats-core/bats-assert libs/bats-assert
fi
BATS=libs/bats/bin/bats
fi
# ---- Run BATS ---------------------------------------------------------------
echo "Running tests with BATS"
export CIPLATFORM
TEST_FILES=(
test_default.bats
test_env_vars.bats
test_secrets.bats
)
# Configure BATS output and parallelization
BATS_FLAGS=();
# Use pretty output when stdout is a terminal; TAP format for CI
if [[ -t 1 ]]; then
BATS_FLAGS+=("-p")
fi
# Parallelize tests if GNU parallel is available
if command -v parallel > /dev/null 2>&1; then
echo "GNU parallel found, running tests in parallel"
BATS_FLAGS+=("--jobs" "$(nproc)")
fi
"$BATS" "${BATS_FLAGS[@]}" "${TEST_FILES[@]}"