Skip to content

PR 2: DI tests (Service, EspClient, runX, persistentPreRunE)#31

Merged
AbsolutOD merged 5 commits into
mainfrom
feature/di-tests
May 9, 2026
Merged

PR 2: DI tests (Service, EspClient, runX, persistentPreRunE)#31
AbsolutOD merged 5 commits into
mainfrom
feature/di-tests

Conversation

@AbsolutOD

Copy link
Copy Markdown
Owner

Summary

PR 2 of 2 implementing the DI and tests spec at docs/superpowers/specs/2026-05-08-di-and-tests-design.md.

This PR is purely additive — new tests against the seams introduced in PR 1 (#30). No production code changes.

  • Commit 1 (test(ssm): cover Service methods via fake ssmAPI) — 13 TestService_* tests covering Save, GetOne, GetMany, Delete, Copy happy paths and AWS error mapping. Local fakeSSMAPI implements the unexported ssmAPI interface; pagination is exercised via a multi-page output sequence.
  • Commit 2 (test(client): cover EspClient wrapper methods) — 11 TestEspClient_* tests covering all six wrapper methods. The non-trivial cases pin the composition order in Copy (re-fetch with decrypt) and Move (Get → Save → Delete with short-circuit on each failure).
  • Commit 3 (test(cmd): cover runX functions via fake EspClient) — 21 TestRun* tests across all seven subcommands. cmd/testutil_test.go provides fakeBackend, newTestEspClient, newCmdWithFlags, testConfig shared across files; the fakeBackend is a deliberate copy of the one in internal/client/client_test.go (two callers, no shared package).
  • Commit 4 (test(cmd): cover persistentPreRunE env-var validation) — 3 TestPersistentPreRunE_* tests covering missing-region, missing-profile, and unsupported-backend error paths. Custom unsetEnv helper because t.Setenv only sets.

Total: 48 new tests across 8 new/modified test files.

Coverage gaps explicitly accepted

Per the spec:

  • ssm.New() — calls config.LoadDefaultConfig, environment-coupled.
  • app.InitQuestions and cmd/init.go — interactive survey.Ask.
  • cmd/get.go::display* — formatting only, no logic.
  • cmd/root.go::configureLogging — sets slog default, no failure path.
  • main.go — single line.

Test plan

  • go build ./... clean
  • go vet ./... clean
  • go test ./... green; all 48 new tests pass
  • No new third-party test dependencies (stdlib testing only)

Notes for review

  • All fakes are local to their consuming package. fakeBackend is duplicated between internal/client/client_test.go and cmd/testutil_test.go rather than promoted to a shared clienttest package — appropriate for two callers, avoids exporting test-only API.
  • One incidental finding (out of scope, flagged for future cleanup): internal/ssm/errors.go::checkSSMByPathError is dead code. The checkSSMError switch has no GetMany case, so it falls through to checkBaseSSMErrors. Caught because TestService_GetMany_ErrorMidIteration succeeds via InternalServerError being recognized by the base mapper, not the per-action one.

AbsolutOD added 5 commits May 9, 2026 13:23
The dispatcher checkSSMError has no GetMany case, so checkSSMByPathError
was never reached at runtime — GetMany falls through to checkBaseSSMErrors
in the default branch. Drop the function and its now-orphaned isolated
test. The TestCheckSSMError dispatcher test continues to pin the
fall-through behavior.
@AbsolutOD AbsolutOD merged commit 700b017 into main May 9, 2026
@AbsolutOD AbsolutOD deleted the feature/di-tests branch May 9, 2026 18:55
Sign up for free to 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.

1 participant