Skip to content

fix(test): make install_docker_engine os-release detection mockable so setup-linux.bats passes on macOS - #233

Merged
saadqbal merged 1 commit into
developfrom
fix/232-os-release-mockable-bats
Jun 9, 2026
Merged

fix(test): make install_docker_engine os-release detection mockable so setup-linux.bats passes on macOS#233
saadqbal merged 1 commit into
developfrom
fix/232-os-release-mockable-bats

Conversation

@saadqbal

@saadqbalsaadqbal commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Closes#232.

Problem

Two bats tests in scripts/tests/setup-linux.bats failed on macOS dev hosts (green in CI on Linux):

  • install_docker_engine: Amazon Linux -> dnf docker
  • install_docker_engine: RHEL clone (#719) -> docker-ce dnf repo

install_docker_engine() gated the Amazon Linux and AlmaLinux/Rocky branches on [[ -f /etc/os-release ]] && grep -qi ... /etc/os-release. The suite mocks grep, but a bash builtin file-test ([[ -f /etc/os-release ]]) can't be intercepted by a function mock. On macOS /etc/os-release doesn't exist, so both branches short-circuited and the function fell through to the get.docker.com path — the asserted strings were never recorded. The pacman/zypper/ubuntu branches passed because they gate on has <cmd> (mockable via PRESENT_CMDS).

CI was unaffected: unit-bash runs on ubuntu (os-release present), and the real RHEL/Amazon docker paths are independently exercised by the distro-prereqs matrix in actual almalinux/amazonlinux containers.

Fix

  • scripts/lib/setup-linux.shinstall_docker_engine reads the os-release path from ${TB_OS_RELEASE_FILE:-/etc/os-release}, used for both the [[ -f ]] test and the grep. Defaults to the exact prior behaviour when the env var is unset (production / CI).
  • scripts/tests/setup-linux.batssetup() writes a real os-release fixture per $TEST_DISTRO to a temp file and exports TB_OS_RELEASE_FILE. This replaces the old grep mock, so distro detection (real [[ -f ]] + real grep) is exercised on every dev host — keeping the coverage meaningful on macOS rather than skipping it.

Verification

  • bats scripts/tests/setup-linux.bats20/20 pass on macOS (was 18/20).
  • Verified on both this host's grep (ugrep 7.5.0) and stock /usr/bin/grep (BSD grep 2.6.0-FreeBSD, GNU-compatible) — the \| BRE and ERE alternations both match, so real grep is robust across macOS dev hosts.
  • No behaviour change when TB_OS_RELEASE_FILE is unset.
  • No new shellcheck findings (additions are quoted; remaining SC2086/SC2016 are pre-existing and untouched).

🤖 Generated with Claude Code


Note

Low Risk
Test-only hook with default path unchanged; no change to installer behavior when TB_OS_RELEASE_FILE is unset.

Overview
Fixes macOS failures in setup-linux.bats for Amazon Linux and AlmaLinux Docker install paths by making os-release detection testable without mocking bash [[ -f ]].

install_docker_engine now reads the os-release path from TB_OS_RELEASE_FILE (default /etc/os-release), used for both the file existence check and grep distro matching. Unset env var keeps production/CI behavior unchanged.

The bats setup() drops the grep mock and adds write_os_release, which writes a temp fixture per TEST_DISTRO and exports TB_OS_RELEASE_FILE. Amazon and RHEL-clone tests call write_os_release so real [[ -f ]] + grep exercise the intended branches on hosts without /etc/os-release.

Reviewed by Cursor Bugbot for commit 2c1d6da. Bugbot is set up for automated code reviews on this repo. Configure here.

…232)
The Amazon Linux and AlmaLinux/Rocky branches of install_docker_engine gated
on `[[ -f /etc/os-release ]] && grep ... /etc/os-release`. The bats suite
mocks `grep`, but a bash builtin file-test can't be intercepted by a function
mock — so on macOS (no /etc/os-release) both branches short-circuited and the
two install_docker_engine distro tests fell through to the get.docker.com
path and failed. CI was green because unit-bash runs on ubuntu.
Read the os-release path from `${TB_OS_RELEASE_FILE:-/etc/os-release}` for
both the file-test and the grep. The bats setup() now writes a real
os-release fixture per $TEST_DISTRO to a temp file and exports
TB_OS_RELEASE_FILE, so distro detection runs for real (real `[[ -f ]]` + real
`grep`) on every dev host. Behaviour is unchanged when the env var is unset
(production / Linux CI).
All 20 tests in scripts/tests/setup-linux.bats now pass on macOS.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@saadqbalsaadqbal self-assigned this Jun 9, 2026
@saadqbal
saadqbal merged commit 9ac0686 into developJun 9, 2026
24 checks passed
@saadqbal
saadqbal deleted the fix/232-os-release-mockable-bats branch July 9, 2026 11:41
Sign up for freeto 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.

3 participants

@saadqbal@aptracebloc@LukasWodka