Back
Open Source

A Go CLI’s tests: config directories, atomic writes and the no-argument path

Leftover #14 added coverage for LEFTOVER_HOME, settings defaults, malformed files, atomic round-trips, help, version and the no-argument app launch path.

JB
Josué Barros
••2 min read

The config and CLI layers had behavior but little direct coverage. A disk cleaner that explains caches, build folders and AI models depends on a correct data directory, a deterministic settings file and a safe atomic write. Those are exactly the paths that are easy to break with a refactor.

This is one of the pull requests behind Six merged PRs in 72 hours. The series looks at the failure, the fix and the review evidence, one merge at a time.

The change: +218 across 2 files. PR 14.

The bug

The PR adds coverage for DataDir with LEFTOVER_HOME and the Unix default, settings defaults, missing and malformed files, dedupe and sort behavior, atomic round-trips, and WriteFileAtomic creating parent directories.

It also covers the CLI surface: help, --version, unknown commands and the no-argument app launch path. The full suite still has a pre-existing TestOllamaModelsAreListed failure on main; this PR does not touch internal/scan.

Why it mattered

Tests around configuration are not glamorous, but they protect the user’s data and the tool’s startup path. A malformed settings file should produce a predictable result, not a partial write or a panic. The no-argument path is what most users run first.

The fix

The change is test-only. It uses temporary directories and controlled environment values to exercise real file behavior rather than mocking the filesystem. That is the right level for DataDir and atomic writes: the bugs live in path resolution and rename semantics.

The evidence

go test ./cmd/leftover ./internal/config passes. The PR reports 0 CodeRabbit findings. The pre-existing failure in internal/scan is documented instead of hidden, which keeps the signal honest.

What I would repeat

Test the paths that decide where data lives and how it is written. A fake filesystem can miss the exact behavior you care about: parent creation, rename atomicity and environment precedence. Also report pre-existing failures instead of pretending the suite is green.

Sources

If this was useful, connect with me on LinkedIn; I write about the bugs behind merged pull requests and the evidence that gets them accepted.

FAQ

What did Leftover #14 test?
Config directory resolution, settings defaults and malformed files, dedupe/sort, atomic file round-trips, parent directory creation, and the help/version/unknown/no-argument CLI paths.
Was any production code changed?
No, the PR is test coverage only.
Does the full suite pass?
The targeted packages pass. A pre-existing TestOllamaModelsAreListed failure in internal/scan remains on main and is outside this PR.
#go#testing#cli#configuration#open-source

Join the Newsletter

Subscribe to get my latest content by email.

We won't send you spam. Unsubscribe at any time.