mirror of
https://github.com/jhillyerd/inbucket.git
synced 2026-10-29 05:32:31 +00:00
47239c08eb
The black-box monitor tests showed socketv1_controller.go and socketv2_controller.go were near-identical: same constants (identical values), upgrader, read/write pumps, Close, and handler bodies, differing only in the event payload shape and v1 dropping deletions. Extract the shared machinery into socket_controller.go: - msgListener[T] generic listener with toStored/toDeleted payload transforms; a nil toDeleted preserves the socketv1 behavior of ignoring deletions - socketReadPump / socketWritePump free functions (WriteJSON is payload-type agnostic) - serveMonitor shared handler body (upgrade, gauge tracking, listener registration, pump wiring) The version files shrink to their listener constructors and the four exported handlers, whose signatures are unchanged. v1 payloads are now shaped at enqueue time rather than write time; the JSON on the wire is identical, pinned by the commit-1 tests, which pass unmodified. Adds direct unit tests for the extracted listener logic: watches() filtering, Receive/Delete filtering + payload shaping, nil-toDeleted deletion dropping, and sequential Close idempotency.