Skip to content

Add BATS tests for image structure and runtime#33

Merged
tobybellwood merged 5 commits intomainfrom
bats-tests
Mar 16, 2026
Merged

Add BATS tests for image structure and runtime#33
tobybellwood merged 5 commits intomainfrom
bats-tests

Conversation

@tobybellwood
Copy link
Copy Markdown
Contributor

@tobybellwood tobybellwood commented Mar 13, 2026

This pull request introduces several improvements to the CI workflow and adds a comprehensive test suite for the Docker image using BATS. The most significant changes include pinning GitHub Actions to specific commit SHAs for improved security, replacing a third-party find-and-replace action with a native shell implementation, and adding new BATS-based image and runtime tests. Additionally, a new Makefile is included to streamline common development and test tasks.

CI/CD Workflow Improvements:

  • All GitHub Actions in .github/workflows/build_and_test.yml are now pinned to specific commit SHAs, increasing security and reproducibility. (actions/checkout, docker/metadata-action, docker/setup-qemu-action, docker/setup-buildx-action, docker/login-action, docker/build-push-action) [1] [2] [3]
  • The test job now uses ubuntu-latest instead of a fixed version, and minor shell quoting improvements were made.
  • The previous use of the jacobtomlinson/gha-find-replace action for updating image tags in example files has been replaced with an inline shell script using sed, removing a dependency and simplifying the workflow.
  • Homebrew setup and package installation steps are now explicit, and BATS tests are run as part of the workflow, including pulling the built image for testing.
  • Docker Compose commands in tests now use the modern docker compose CLI instead of the legacy docker-compose.

Testing Enhancements:

  • Added a Makefile with targets for building the image, running BATS tests (all, structure-only, runtime-only), validating HAProxy config, starting/stopping the stack, and cleaning up images, making local development and testing easier.
  • Introduced tests/image_structure.bats, a suite of tests verifying the presence of binaries, files, configuration, and exposed ports in the image.
  • Introduced tests/runtime.bats, a suite of runtime and integration tests that start containers, check HAProxy and docker-gen processes, verify the stats endpoint, and test backend discovery logic.

Minor Workflow and Test Adjustments:

  • Improved grep usage in image reference checks by adding the -F flag for fixed string matching. [1] [2]
  • Updated Homebrew package installation logic for better reliability and clarity.

Summary of Most Important Changes:

1. CI/CD Workflow Hardening & Modernization

  • Actions in .github/workflows/build_and_test.yml are now pinned to commit SHAs; replaced deprecated/third-party actions with native shell and modernized Docker Compose usage. [1] [2] [3] [4] [5]

2. Test Suite Expansion

  • Added tests/image_structure.bats for image structure validation and tests/runtime.bats for runtime and integration testing using BATS. [1] [2]

3. Developer Experience Improvements

  • Added a Makefile with targets for building, testing, and managing the Docker image and test runs, simplifying local development workflows.

4. Workflow Reliability Enhancements

  • Improved shell quoting, environment variable handling, and grep usage for more robust and predictable CI runs. [1] [2] [3]

5. Homebrew and Package Management

  • Explicit Homebrew setup and package installation steps ensure all test dependencies are installed in CI.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands CI validation for the HAProxy Docker image by adding BATS-based image structure and runtime/integration tests, alongside workflow hardening/modernization and a developer Makefile to run common tasks locally.

Changes:

  • Add BATS test suites for image structure verification and runtime/backend discovery checks.
  • Update CI workflow to pin most actions, replace a third-party find/replace action with shell+sed, install test deps via Homebrew, and run the new BATS tests.
  • Introduce a Makefile to simplify building, testing, and basic container operations.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
.github/workflows/build_and_test.yml Pins actions (mostly), replaces find/replace action with sed, installs deps, pulls image, runs BATS tests, and modernizes some Docker Compose usage.
tests/image_structure.bats Adds container-image “baked-in” checks (binaries, files, env, exposed ports, basic HAProxy validation).
tests/runtime.bats Adds runtime/integration tests that start the container, check processes and /stats, and validate backend discovery via docker-gen.
Makefile Adds local targets for build/test (BATS), config validation, and starting/stopping the stack.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/build_and_test.yml Outdated
Comment thread Makefile Outdated
Comment thread tests/runtime.bats Outdated
Comment thread tests/runtime.bats Outdated
Comment thread .github/workflows/build_and_test.yml
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens and modernizes the CI workflow while adding a BATS-based test suite to validate the built HAProxy Docker image’s structure and runtime behavior.

Changes:

  • Pin GitHub Actions to commit SHAs, replace a third-party find/replace action with sed, and modernize CI steps (incl. docker compose).
  • Add BATS tests for image structure (tests/image_structure.bats) and runtime/integration behavior (tests/runtime.bats).
  • Introduce a Makefile to streamline local image builds and test execution.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
.github/workflows/build_and_test.yml Pins actions, replaces find/replace action with sed, installs BATS via Homebrew, pulls the built image, and runs the new BATS suites in CI.
Makefile Adds developer-friendly targets for building the image and running BATS test subsets, plus common stack utilities.
tests/image_structure.bats Validates expected binaries, baked-in files/config, metadata (exposed ports), and basic HAProxy functionality.
tests/runtime.bats Starts a long-running container and performs runtime checks, stats endpoint validation, and backend discovery integration tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/runtime.bats Outdated
Comment thread tests/runtime.bats Outdated
Comment thread tests/runtime.bats
Comment thread tests/runtime.bats
@tobybellwood tobybellwood marked this pull request as ready for review March 16, 2026 02:23
@tobybellwood tobybellwood requested a review from Copilot March 16, 2026 02:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a BATS-based test suite for validating the built HAProxy image (structure + runtime behavior) and hardens/modernizes the CI workflow by pinning actions, simplifying tag replacement, and running the new tests in CI.

Changes:

  • Add BATS tests for image structure validation and runtime/integration behavior.
  • Update CI workflow to pin actions by SHA, replace a third-party find/replace action with sed, and run BATS tests against the built image.
  • Add a Makefile to streamline local build/test workflows.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
.github/workflows/build_and_test.yml Pins actions, replaces find/replace with shell, installs deps via Homebrew, pulls built image, runs BATS tests, modernizes compose usage.
Makefile Adds local developer targets for build, BATS test runs, config validation, compose up/down, etc.
tests/image_structure.bats Adds container/image “baked-in” checks (binaries, required files, env, exposed ports).
tests/runtime.bats Adds runtime checks (container health, processes, stats endpoint) and backend discovery integration tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/runtime.bats Outdated
Comment thread tests/runtime.bats Outdated
Comment thread tests/runtime.bats Outdated
Comment thread .github/workflows/build_and_test.yml Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens and modernizes CI while adding BATS-based validation for the published Docker image (both “built image structure” and “running container behavior”), plus a Makefile to simplify local workflows.

Changes:

  • Pin GitHub Actions to commit SHAs and replace a third-party find/replace action with a native find + sed implementation.
  • Add BATS test suites for image structure and runtime/integration behavior (including backend discovery via docker-gen + HAProxy stats).
  • Add a Makefile to build the image and run the new test suites locally.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
.github/workflows/build_and_test.yml Pins actions by SHA, installs BATS in CI, pulls built image, and runs the new BATS suites.
Makefile Adds local targets for building, testing (BATS), config validation, and compose lifecycle.
tests/image_structure.bats Validates image contents/metadata (binaries, files, env, exposed ports).
tests/runtime.bats Runs a long-lived container and exercises runtime behavior (process checks, /stats, backend discovery).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/runtime.bats
Comment thread .github/workflows/build_and_test.yml
Comment thread .github/workflows/build_and_test.yml
@tobybellwood tobybellwood merged commit df094c4 into main Mar 16, 2026
6 checks passed
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.

2 participants