fix(write-tests): boundary/wire mocking over interface fakes - #1
Open
ajcarberry wants to merge 1 commit into
Open
fix(write-tests): boundary/wire mocking over interface fakes#1ajcarberry wants to merge 1 commit into
ajcarberry wants to merge 1 commit into
Conversation
The skill taught patterns that a real Go CLI testing effort found to be anti-patterns. Bring it in line. - Replace the three-layer strategy (which framed interface-based fakes as a legitimate boundary approach) with boundary-first testing: fake the executable on PATH and assert the real argv, or httptest and assert the method/path/body. Drop the CommandRunner interface pattern — asserting "Run was called" proves the code called the fake, not that it built the right command, and it couples tests to a test-only interface. - Stop recommending t.Skip() when the binary is absent — that is a false-green (the coverage gate runs `go test` without building first). Build the binary in TestMain; a miss is a hard failure. Note that subprocess tests don't count toward a package's coverage, so command logic needs in-process cobra tests (with an os.Stdout capture helper, since commands print via fmt.Printf, not cmd.OutOrStdout). - Switch examples from testify to stdlib `testing` (t.Fatalf preconditions, t.Errorf checks, reflect.DeepEqual, errors.Is/As) to match stdlib codebases; keep a note to match testify only where a project already uses it. - Add the "prove the negative" pattern for destructive ops (fake fails the test on any mutating call) and a Determinism section (map-iteration and unseeded-RNG bugs). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AfCuqUGhxYxbvo4FgkBtFm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
write-testsskill taught three things that a real Go CLI testing effort (in a downstream repo) found to be anti-patterns. This brings the skill in line with what actually works.Changes
CommandRunner,assert fake.Calls[0][0]=="nomad") proves the code called a fake, not that it built the right command, and couples tests to a test-only interface. Replaced with: fake the executable onPATHand assert the real argv (sharedinternal/testutil.FakeExec), orhttptestand assert method/path/decoded-body.t.Skip()on a missing binary. That is a false-green — if the coverage gate runsgo testwithout building first, the E2E tests silently pass.TestMainbuilds the binary; a miss is a hard failure. Added the note that subprocess tests don't count toward a package's coverage, so command logic needs in-process Cobra tests (with anos.Stdoutcapture helper, since commands print viafmt.Printf, notcmd.OutOrStdout()).testing. The reference mandated testify while the codebases it targets use stdlib. Converted the examples; kept a note to match testify only where a project already standardises on it.Kept as-is: table-driven structure, naming,
t.Helper(), golden files, TUI state-transition testing, parallelism guidance.Companion to the downstream ADR that codifies these tenets (homelab-monorepo ADR-0027).
🤖 Generated with Claude Code