You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test: address 17 Copilot-flagged test-rigor concerns from #548 (#552)
Closes#549
Follow-up to #548 (coverage 24.4% → 82.5%). Copilot flagged 17
test-quality
concerns that merged alongside the coverage uplift; this PR addresses
all of
them as a focused test-rigor pass. No production code behaviour changes.
## Per-concern status
### Goroutine lifecycle (7 threads) — fixed
- `newAppForCoverage` now calls `registerAppShutdown(t, app)` which
installs
`t.Cleanup(app.Shutdown)`, shutting down `periodicCacheLogging`,
template-cache cleanup, and rate-limiter cleanup goroutines. Every test
built on `newAppForCoverage` (`TestNewApp_*`, `TestApp_*`,
`TestUserModifyHandler_AuthenticatedPaths`, `TestGroupModifyHandler_*`,
`TestModifyHandlers_DirectNoCSRF`, `TestCSRFProtectedModifyHandlers`,
`TestAuthenticatedGETHandlers`) now tears down cleanly. The cleanup is
defensive: if a test calls Shutdown explicitly first, the cleanup
recovers
from the `close(stopCacheLog)` panic on second call.
- `TestNewApp_WithPersistSessions` keeps its explicit Shutdown because
it
asserts on the return value; it does not also register the cleanup.
### port 65535 flaky assumption — fixed
`TestRunHealthCheck/returns 1 when no server is listening` now uses
`net.Listen("tcp", "127.0.0.1:0")` to acquire a known-free ephemeral
port,
closes it, and reuses the port number.
### `testTemplateRenderError` sad-path assertion — fixed
`TestRender_WithCancelledContext` (the cancelled-context render test)
now
asserts `err != nil` and `errors.Is(err, context.Canceled)` instead of
only
`t.Logf`-ing on mismatch. A silent nil return from Render with a
cancelled
context is now a fail.
### Comment/behaviour mismatch (no-op middleware) — fixed
Removed the `bare.Use(func(c *fiber.Ctx) error { /* attach cookies */
return c.Next() })`
block in `TestModifyHandlers_DirectNoCSRF`. Cookies are attached
per-request
via `postTo`; no middleware is needed.
### No-assertion test variants — fixed
`Users(nil, ...)`, `Groups(nil)`, and `Computers(nil)` render blocks in
`render_test.go` now use `require.NoError` +
`require.NotZero(buf.Len())` so
the empty-state branch is actually verified.
### `-coverpkg` scope too wide — fixed
The reusable `netresearch/.github/.github/workflows/go-check.yml` has no
hook
between `go test` and threshold enforcement, so we cannot post-filter
`coverage.out` via inputs. Fix:
- Call the reusable workflow with `enable-build-test: false` and
`enable-codecov: false`, keeping smoke/fuzz/license/security jobs.
- Add an inline `build-test-coverage` job that expands `-coverpkg` to
include
`internal/web/templates/...`, filters `*_templ.go` lines out of
`coverage.raw.out` → `coverage.out`, then enforces the 80% threshold and
uploads to Codecov.
Authored helpers in `internal/web/templates` (`flash.go` Flashes /
SuccessFlash / ErrorFlash / InfoFlash / IsSuccess / IsError / IsInfo /
BorderColor, `specializeUsers`/`specializeGroups`/`specializeComputers`,
`formatLastLogon`, `getNavbarClasses`) now count toward the 80% floor.
The
generated `*_templ.go` files do not. `.github/template.yaml` drift note
updated.
### `StatusCode == 0` always-true assertions — fixed
Replaced the nine `StatusCode == 0` / `NotEqual(0, StatusCode)` checks
across
`server_coverage_test.go`, `handlers_authenticated_test.go`,
`modify_handlers_test.go`, `server_test.go`, and
`ldap_integration_test.go`
with explicit expected-code lists (200/302/403/404/500/503 as
appropriate).
`TestApp_RoutesRegistered` now uses a `wantCodes []int` slice per route
so
each is validated against the code(s) the registered handler actually
emits
(302 for protected routes without session, 200 for `/login`, 200-or-503
for
`/health*`).
### Misleading `cancel()` in ListenCancelled — fixed
Renamed `TestApp_ListenCancelled` → `TestApp_ListenGracefulShutdown`.
The
test no longer passes a cancellable context (Listen forwards to
`fiber.Listen` and doesn't observe ctx), and now asserts Listen returns
within 2s of `Shutdown()`.
### Stale file-header comment — fixed
`login_handler_test.go` header previously advertised "successful login
with
regenerated session"; no such case exists. Replaced with a header that
matches actual contents and notes the success case is in the LDAP
integration suite.
## Verification
- `go test -race -timeout 120s ./...` passes all packages.
- `golangci-lint run --timeout 3m ./...` is clean (0 issues).
- Filtered coverage: **82.6%** (up from 82.5% baseline — now includes
`flash.go` authored helpers at 100%).
## Test plan
- [x] All existing tests pass under `-race`
- [x] `golangci-lint` reports 0 issues
- [x] Filtered coverage >= 80% threshold
- [x] `flash.go` helpers visible in coverage output
- [x] `TestApp_RoutesRegistered` asserts specific status codes per route
- [x] `TestRender_WithCancelledContext` fails if Render returns nil
error
- [x] `TestRunHealthCheck` no-server case uses ephemeral port
0 commit comments