Context
PR #18 upgraded GitHub Actions but had to pin bats-core at v1.2.1 because newer versions (1.7+) hang on the test suite. The root cause is well-understood and the fix is straightforward.
Problem
bats-core 1.7+ changed behavior: it now waits for all background processes spawned during setup_file() to exit before considering a test file complete. Two test files start ec2-metadata-mock as a background process in setup_file() but never kill it in teardown_file():
test/aws-credentials.bats
test/vault-iam-auth.bats
This causes bats to hang indefinitely after all tests pass, waiting for the mock to exit.
Fix
Add pkill -f ec2-metadata-mock || true to teardown_file() in both files:
function teardown_file() {
pkill -f ec2-metadata-mock || true
unset EC2_METADATA_MOCK
}
Once that's in place, update .github/workflows/bats-unit.yml to install a modern bats version:
- name: Setup BATS
shell: bash
run: |
git clone --depth 1 --branch v1.11.1 https://github.com/bats-core/bats-core.git /tmp/bats-core
sudo /tmp/bats-core/install.sh /usr/local
Verification
After making the changes:
- Run
bats test/requirements.bats to confirm bats is functional
- Run each test file individually and confirm it exits cleanly:
bats test/aws-credentials.bats
- Run the full suite sequentially to confirm no port conflicts between files
Additional notes
test/gcp-credentials.bats and test/vault-gce-auth.bats may have a similar pattern with the GCE metadata mock — check those too
- The
3>&- trick on the ec2-metadata-mock launch line was a workaround for older bats FD inheritance; it's no longer sufficient in 1.7+
- Current pinned version (v1.2.1) works but misses years of bats improvements (parallel test execution, better TAP output, etc.)
Context
PR #18 upgraded GitHub Actions but had to pin
bats-coreat v1.2.1 because newer versions (1.7+) hang on the test suite. The root cause is well-understood and the fix is straightforward.Problem
bats-core1.7+ changed behavior: it now waits for all background processes spawned duringsetup_file()to exit before considering a test file complete. Two test files startec2-metadata-mockas a background process insetup_file()but never kill it inteardown_file():test/aws-credentials.batstest/vault-iam-auth.batsThis causes bats to hang indefinitely after all tests pass, waiting for the mock to exit.
Fix
Add
pkill -f ec2-metadata-mock || truetoteardown_file()in both files:Once that's in place, update
.github/workflows/bats-unit.ymlto install a modern bats version:Verification
After making the changes:
bats test/requirements.batsto confirm bats is functionalbats test/aws-credentials.batsAdditional notes
test/gcp-credentials.batsandtest/vault-gce-auth.batsmay have a similar pattern with the GCE metadata mock — check those too3>&-trick on theec2-metadata-mocklaunch line was a workaround for older bats FD inheritance; it's no longer sufficient in 1.7+