testing
Technical notes on web development, DevOps, and AI integration.
83 articles
- 21:24backend
The Safe Boundary: Why the Roundtrip Test Stops at Checkpoint 56
The down chain breaks mid-way: an old down migration inserts an ENUM value that no longer exists there. Checkpoint 56 is the tested safe window.
TL;DR: The migration roundtrip test stops at version 56 instead of unwinding to zero, because a cross-dependency between migrations 45 and 51 breaks any deeper descent. Version 56 is the deepest proven-safe checkpoint, verified with spot-checks on 8 tables and 12 columns. A separate test pins the dev-only login route to return 404 everywhere except development.
#golang#golang-migrate#mysql - 20:45testing
Coverage Percentage Is Not a Shield: Lock the Reject Arms
A Go middleware coverage audit from 27 to 96.7 percent: what httptest arm-by-arm reject-path testing teaches, from JWT to CORS.
TL;DR: A coverage audit showed middleware at 27 percent despite guarding authentication, and the untested paths were all security-critical rejections. Walking arm by arm with Go's httptest added 850 lines across seven files, pushing middleware to 96.7 percent without changing production code. Coverage stops climbing where fakes start lying, so each rejection arm now gets a named test immediately.
#golang#testing#security - 14:00security
Five Security Holes, Locked Instead of Fixed
A tests-only commit turns five weak authentication behaviors into a named inventory with owner-decision markers.
TL;DR: Instead of silently fixing five weak security behaviors, the author locked them as characterization tests with owner-decision markers. Findings include account enumeration via registration, unthrottled OTP verification, non-revoked JWTs, orphaned OTP rows, and in-memory rate-limiter state. Mapping first beats fixing from memory: each weakness becomes a prioritized decision ticket.
#testing#security#authentication - 13:09backend
Review Moderation State Machine: State Transition Validation Through Integration Testing
Integration tests prove the review moderation machine: a wrong 9.9/999 seed, Remove filling the audit trail, Restore clearing it, aggregates recomputed both ways.
TL;DR: Integration tests inject absurd aggregates and verify Remove triggers real recalculation through production logic, not test-only updates. The moderation flow atomically flips approved to removed, fills four audit columns, enforces whitelisted reasons, and blocks double removal with ErrNotFound, while restore reverses everything. Table-driven tests covering boundaries, duplication, and pagination turn state transitions into a guaranteed contract.
#go#testing#mysql - 12:14testing
The Sneaky LIKE Assertion: When 1 Catches 19
A LIKE pattern over serialized JSON made an integration assertion flaky: object 1 caught object 19 through a substring collision.
TL;DR: A LIKE pattern meant to find JSON object 1 also matched objects 16 and 19, since substring matching treats them as prefixes. The flake hid because fixture ordering kept the right row first until data shifted. Fix by comparing parsed values or using JSON functions like JSON_SEARCH instead of loose string matching.
#testing#mysql#flaky-tests - 12:05testing
Characterization Tests: Recording Behavior, Not Judging It
Characterization tests lock in what code actually does while product decisions stay pending, guarded by a pending marker above the assertion.
TL;DR: Characterization tests document current behavior, not correctness; a failure means something changed, not broke. The author found pending-decision markers above such tests and realized the odd procedure—write a failing assertion, replace it with actual output—is intentional. A passing test guards deferred decisions better than any comment, letting owners decide later through one honest commit.
#testing#characterization-testing#refactoring - 11:31backend
Repository Contract at the SQL Line
Integration tests lock the repository contract at the SQL line: mapping error 1062 to a Go sentinel, soft-delete visibility, and pagination clamps on MySQL.
TL;DR: Binding a time function as a string parameter silently failed in MySQL because parameter markers only accept data values, not SQL expressions, so the fix splits inserts into two branches calling the function inline. Integration tests now lock the repository contract, mapping driver error 1062 to ErrSlugTaken via errors.Is. repository_lifecycle_test.go covers visibility, soft deletes, sorting, and pagination clamps.
#go#testing#mysql - 06:05testing
A Relative Test Path That Went Astray
A mechanical test-tree reorganization broke migration tests: relative paths bind to directory depth, not module root. One level deeper and the ladder ran out.
TL;DR: A directory reorg broke migration tests because go test runs from the test file's location, not the module root. The hardcoded relative path depth ladder went stale, resolving one level short of the migrations folder. Fix: re-derive paths from the new location and list attempted depths in failure messages.
#go#testing#database - 05:56testing
Three Seams an External Test Package Forces
Moving tests out of the package is not a file operation. Three Go modules forced three seam shapes: a TTL state reader, injected sleep, a mirror oracle.
TL;DR: Moving Go tests outside their package turned out to be a contract audit: every hidden internal needed an exported seam. Three flavors emerged—a status reader (StoredTTL) to skip sleeps, dependency injection (RetryConnect's swappable sleep), and a mirror oracle (AllModules) to prevent tautological tests. Production behavior stayed completely unchanged.
#go#testing#refactoring