Skip to content

setup-linux.bats: 2 install_docker_engine tests fail on macOS dev hosts (un-mockable /etc/os-release file-test) #232

@saadqbal

Description

@saadqbal

Symptom

Two bats tests in scripts/tests/setup-linux.bats fail when run on a macOS dev host (they pass in CI on Linux):

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

Root cause

install_docker_engine() in scripts/lib/setup-linux.sh gated the Amazon Linux and AlmaLinux/Rocky branches with [[ -f /etc/os-release ]] && grep -qi ... /etc/os-release. The test mocked grep to simulate os-release content per $TEST_DISTRO, but a bash builtin file-test ([[ -f /etc/os-release ]]) cannot be intercepted by a function mock. On macOS /etc/os-release does not exist, so both branches short-circuited and the function fell through to the get.docker.com path — the expected strings were never recorded and the asserts failed.

The pacman/zypper/ubuntu branches passed because they gate on has <cmd> (mockable via PRESENT_CMDS), not a file-test.

CI was unaffected: the unit-bash job 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 (Option 2 — keep coverage on macOS dev machines)

Make the os-release lookup mockable: install_docker_engine reads from ${TB_OS_RELEASE_FILE:-/etc/os-release} for both the [[ -f ]] test and the grep. The bats setup() writes a real os-release fixture per $TEST_DISTRO to a temp file and exports TB_OS_RELEASE_FILE, so distro detection (real [[ -f ]] + real grep) is exercised on every dev host. Default behaviour is unchanged when the env var is unset (production / CI).

Acceptance criteria

  • bats scripts/tests/setup-linux.bats — all 20 tests pass on macOS.
  • No behaviour change when TB_OS_RELEASE_FILE is unset (production / Linux CI).
  • No new shellcheck findings.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions