test(tpagectl): add comprehensive test suite #612
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
thwap/thwap-pagesd!612
Loading…
Reference in a new issue
No description provided.
Delete branch "test/tpagectl-test-suite"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Implements Phase 8 test coverage (roadmap #288).
roundTripFuncmockhttp.RoundTrippercovering the previously-untesteddo()branches (JSON encode-request error, decode-response error on a 2xx with invalid JSON) plus mock-driven bearer-token attachment. Client coverage → 90.9%.cmd/tpagectl/integration_test.gowith a stateful fake daemon (httptest) implementing the full/api/v1surface +/healthz//readyz, running the real root command end-to-end (config → client → command → output → exit code): site lifecycle (create/list/get/update/delete), deployment list/get/promote/rollback, preview deploy/list/get/delete, status,--format json/yaml, and exit-code classification (not-found 4, validation 5). Running the actual daemon requires Forgejo+K8s, noted as out of scope.internal/tpagectl/testutil.Goldenwith a-updateflag;.goldenfiles for site list (table/json), site get, deployment list, preview list, status, and root--help.credentials3.8% → 88.5% via an injectableopenKeyringopener tested withkeyring.NewArrayKeyring; gap tests forconfig(→81.9%),docs(→89.3%),auth(→87.3%),interactive(→72.8%; the TTY-gated picker path is documented as not unit-testable). Added a Makefilecoveragetarget gating weighted coverage of./internal/tpagectl/... ./cmd/tpagectl/...at ≥80%.Why
Roadmap task #288.
Testing
go test -race ./...passes (30 packages)make coveragereports 86.4% and passes the ≥80% gategolangci-lint runcleanBreaking Changes
None.
credentials.open()now uses an injectableopenKeyringvar (defaultkeyring.Open); behavior unchanged.Notes
The interactive
ResolveSiteTTY path (raw-mode fuzzy picker) cannot be unit-tested without a pty; itsselectInteractivecore is covered via synthetic key bytes. CI enforcement of the coverage gate is deferred to task #293 (CI pipeline).Closes #284
Closes #285
Closes #286
Closes #287
Excellent test suite. The stateful fake daemon covers the full
/api/v1surface end-to-end (config → client → command → output → exit codes) with deterministic ordering (slice-based payloads, substring assertions on the map-order list), thecredentialstests close the #593 coverage gap cleanly via the injectableopenKeyring(with awithOpenerrestore-helper, covering unavailable/genuine-failure/notfound paths), golden tests use fixed-body servers for determinism, and the Makefile coverage gate math is correct. Approving; no new issues — the CI enforcement gap is already tracked as #293.Notes (non-blocking)
cmd/tpagectl/integration_test.go:493–var _ = fmt.Sprintfis a dummy keeping an unusedfmtimport; trivial cleanup.credentials.openKeyringis a mutable package-global for test injection — safe today (not.Parallel), but a latent footgun if parallel tests are added later.root-help.goldenis brittle by design (help output changes with any flag/command addition); standard golden-test tradeoff.Praise
roundTripFuncmock covers the previously-untesteddo()encode/decode-error branches and bearer-token attachment.--token/--server, keeping the keychain out of the path.