Skip to content

Use bats-assert library functions in BATS test suite - #2018

Merged
PromoFaux merged 3 commits into
developmentfrom
copilot/update-bats-tests-based-on-feedback
Mar 30, 2026
Merged

Use bats-assert library functions in BATS test suite#2018
PromoFaux merged 3 commits into
developmentfrom
copilot/update-bats-tests-based-on-feedback

Conversation

Copilot AI commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

As suggested by @casperklein, replace manual shell assertions with bats-assert library functions for cleaner tests and better failure output (expected vs. actual diffs on failure).

Changes

  • test/run.sh: Install bats-support and bats-assert alongside bats-core, pinned to specific versions (v0.3.0 / v2.1.0) and overridable via BATS_SUPPORT_VERSION / BATS_ASSERT_VERSION
  • test/test_suite.bats: Load the libraries and replace manual assertions throughout:
    • [ "$status" -eq 0 ]assert_success
    • [[ "$output" == *"..."* ]]assert_output --partial "..."
    • [ "$output" = "..." ]assert_output "..."
    • In the shutdown test (logs captured to a variable rather than via run), pipe through run echo "$logs" to make assert_output --partial usable

Before / After

# Before
run docker exec "$CONTAINER_DEFAULT" pihole-FTL -vv
[ "$status" -eq 0 ]
[[ "$output" == *"Version:"* ]]

# After
run docker exec "$CONTAINER_DEFAULT" pihole-FTL -vv
assert_success
assert_output --partial "Version:"

Agent-Logs-Url: https://github.com/pi-hole/docker-pi-hole/sessions/a7bafe62-d413-4878-8d02-520f208d2812

Co-authored-by: PromoFaux <1998970+PromoFaux@users.noreply.github.com>
Copilot AI changed the title [WIP] Update BATS tests based on comments from Casperklein Use bats-assert library functions in BATS test suite Mar 30, 2026
Copilot AI requested a review from PromoFaux March 30, 2026 10:26
@PromoFaux
PromoFaux marked this pull request as ready for review March 30, 2026 10:27
@PromoFaux
PromoFaux requested a review from a team as a code owner March 30, 2026 10:27
Comment thread test/run.sh Outdated
Signed-off-by: Adam Warner <github@adamwarner.co.uk>
@PromoFaux
PromoFaux merged commit f658655 into development Mar 30, 2026
15 checks passed
@PromoFaux
PromoFaux deleted the copilot/update-bats-tests-based-on-feedback branch March 30, 2026 11:03
@T-o-m-H-u

Copy link
Copy Markdown

The changelog suggests this to be the first AI generated code in pi-hole–sort of, since this only affects code test.

Does the project plan on writing an AI code policy, to make the use of such code and its review process transparent to users?

@yubiuser

Copy link
Copy Markdown
Member

Does the project plan on writing an AI code policy, to make the use of such code and its review process transparent to users?

Sounds reasonable.

@PromoFaux

Copy link
Copy Markdown
Member

I don't suppose I've ever really considered it. Can you point to some other projects that implement such a policy?

@T-o-m-H-u

Copy link
Copy Markdown

@PromoFaux Sure, there are plenty. The arguments for and against AI generated code are rather well hashed out already. I link to the Linux policy as an example, as others are to be found. There is probably a better place for discussion, than this PR.

Linux AI policy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants