-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Various AI inspired code changes (And MOAR TESTS) #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a2cc9b9
fix: log error if crontab install fails in start_cron()
PromoFaux b5826b6
test: add coverage for ADDITIONAL_PACKAGES and TAIL_FTL_LOG
PromoFaux 1f356d2
refactor: replace eval with bash array in build.sh
PromoFaux acd1cf7
refactor: move container lifecycle management into BATS test files
PromoFaux 9fc8cd3
test: expand Docker container test coverage
PromoFaux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/usr/bin/env bash | ||
| # Shared container helper functions for BATS test files | ||
|
|
||
| start_container() { | ||
| local platform_args=() | ||
| [ -n "${CIPLATFORM:-}" ] && platform_args=(--platform "${CIPLATFORM}") | ||
| docker run -d -t "${platform_args[@]}" -e TZ="Europe/London" "$@" pihole:test | ||
| } | ||
|
|
||
| wait_for_log() { | ||
| local container="$1" | ||
| local pattern="$2" | ||
| local timeout=60 | ||
| local elapsed=0 | ||
| printf "Waiting for '%s' in %.30s... " "${pattern}" "${container}" | ||
| until docker logs "${container}" 2>&1 | grep -q "${pattern}"; do | ||
| sleep 1 | ||
| elapsed=$(( elapsed + 1 )) | ||
| if (( elapsed >= timeout )); then | ||
| echo "TIMEOUT" | ||
| echo "--- Container logs ---" | ||
| docker logs "${container}" | ||
| return 1 | ||
| fi | ||
| done | ||
| echo "ready (${elapsed}s)" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| #!/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:" | ||
| } | ||
|
|
||
| # ---- Container services ----------------------------------------------------- | ||
|
|
||
| @test "crond is running" { | ||
| run docker exec "$CONTAINER" pgrep crond | ||
| assert_success | ||
| } | ||
|
|
||
| @test "Logrotate config is installed" { | ||
| run docker exec "$CONTAINER" test -f /etc/pihole/logrotate | ||
| assert_success | ||
| } | ||
|
|
||
| # ---- Default configuration -------------------------------------------------- | ||
|
|
||
| @test "Default DNS upstreams are applied when none are configured" { | ||
| run docker exec "$CONTAINER" pihole-FTL --config -q dns.upstreams | ||
| assert_success | ||
| assert_output --partial "8.8.8.8" | ||
| assert_output --partial "8.8.4.4" | ||
| } | ||
|
|
||
| # ---- Web interface ---------------------------------------------------------- | ||
|
|
||
| @test "Web interface is accessible" { | ||
| run docker exec "$CONTAINER" curl -sf /dev/null http://localhost/admin/ | ||
| assert_success | ||
| } | ||
|
|
||
| # ---- Docker image ----------------------------------------------------------- | ||
|
|
||
| @test "/pihole.docker.tag is present" { | ||
| run docker exec "$CONTAINER" test -f /pihole.docker.tag | ||
| assert_success | ||
| } | ||
|
|
||
| @test "macvendor.db is present" { | ||
| run docker exec "$CONTAINER" test -f /macvendor.db | ||
| assert_success | ||
| } | ||
|
|
||
| @test "macvendor.db path is configured in FTL" { | ||
| run docker exec "$CONTAINER" pihole-FTL --config -q files.macvendor | ||
| assert_success | ||
| assert_output "/macvendor.db" | ||
| } | ||
|
|
||
| # ---- Runtime ---------------------------------------------------------------- | ||
|
|
||
| @test "FTL is running as the pihole user" { | ||
| run docker exec "$CONTAINER" pgrep -u pihole pihole-FTL | ||
| assert_success | ||
| } | ||
|
|
||
| @test "Capabilities are applied to pihole-FTL" { | ||
| run docker exec "$CONTAINER" getcap /usr/bin/pihole-FTL | ||
| assert_success | ||
| assert_output --partial "cap_net_raw" | ||
| } | ||
|
|
||
| # ---- 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)" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.