Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ if [ -z "${BATS:-}" ]; then
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.1.0}" https://github.com/bats-core/bats-assert libs/bats-assert
Comment thread
PromoFaux marked this conversation as resolved.
Outdated
fi
BATS=libs/bats/bin/bats
fi

Expand Down
42 changes: 23 additions & 19 deletions test/test_suite.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bats

load 'libs/bats-support/load'
load 'libs/bats-assert/load'

# Containers are started by run.sh and their IDs exported as environment
# variables. All tests (except the shutdown test) share these containers,
# so each configuration is only booted once per test run.
Expand All @@ -11,16 +14,16 @@

@test "FTL reports version" {
run docker exec "$CONTAINER_DEFAULT" pihole-FTL -vv
[ "$status" -eq 0 ]
[[ "$output" == *"Version:"* ]]
assert_success
assert_output --partial "Version:"
}

@test "FTL reports correct architecture" {
[ -n "${CIPLATFORM:-}" ] || skip "CIPLATFORM not set, running locally"
run docker exec "$CONTAINER_DEFAULT" pihole-FTL -vv
[ "$status" -eq 0 ]
[[ "$output" == *"Architecture:"* ]]
[[ "$output" == *"$CIPLATFORM"* ]]
assert_success
assert_output --partial "Architecture:"
assert_output --partial "$CIPLATFORM"
}

@test "FTL starts up and shuts down cleanly" {
Expand Down Expand Up @@ -50,47 +53,48 @@
logs=$(docker logs "$container" 2>&1)
docker rm "$container"

[[ "$logs" == *"INFO: ########## FTL terminated after"* ]]
[[ "$logs" == *"(code 0)"* ]]
run echo "$logs"
assert_output --partial "INFO: ########## FTL terminated after"
assert_output --partial "(code 0)"
}

@test "FTLCONF_ variables successfully configure FTL" {
run docker exec "$CONTAINER_CUSTOM" pihole-FTL --config
[ "$status" -eq 0 ]
[[ "$output" == *"dns.upstreams = [ 8.8.8.8, 1.1.1.1 ]"* ]]
[[ "$output" == *"webserver.port = 8080"* ]]
assert_success
assert_output --partial "dns.upstreams = [ 8.8.8.8, 1.1.1.1 ]"
assert_output --partial "webserver.port = 8080"
}


# ---- Container configuration ------------------------------------------------

@test "Cron file is valid" {
run docker exec "$CONTAINER_DEFAULT" /usr/bin/crontab /crontab.txt
[ "$status" -eq 0 ]
assert_success
}

@test "Custom PIHOLE_UID is applied to pihole user" {
run docker exec "$CONTAINER_CUSTOM" id -u pihole
[ "$status" -eq 0 ]
[ "$output" = "456" ]
assert_success
assert_output "456"
}

@test "Custom PIHOLE_GID is applied to pihole group" {
run docker exec "$CONTAINER_CUSTOM" id -g pihole
[ "$status" -eq 0 ]
[ "$output" = "456" ]
assert_success
assert_output "456"
}

# ---- Web password setup -----------------------------------------------------

@test "Random password is assigned on fresh start" {
run docker logs "$CONTAINER_DEFAULT"
[ "$status" -eq 0 ]
[[ "$output" == *"assigning random password:"* ]]
assert_success
assert_output --partial "assigning random password:"
}

@test "Password defined by environment variable is used" {
run docker exec "$CONTAINER_CUSTOM" bash -c ". bash_functions.sh; setup_web_password"
[ "$status" -eq 0 ]
[[ "$output" == *"Assigning password defined by Environment Variable"* ]]
assert_success
assert_output --partial "Assigning password defined by Environment Variable"
}
Loading