Cybersecurity-Projects/PROJECTS/beginner/canary-token-generator/backend/internal
CarterPerez-dev 82085711b6 test(canary): testcontainers integration test for trigger + dedup + retention
Closes deferred Phase-9 item 1 (testcontainers full-flow test) and
exercises the Phase 10 dedup gate, retention loop, and notify writeback
end to end.

internal/event/integration_test.go (build tag integration):

- TestIntegration_FullCreateAndTriggerFlow: spins up testcontainers
  Postgres + miniredis, builds the same chi router shape main.go uses
  (RequestID + Recovery + tokenH.RegisterTriggerRoutes + /api subrouter
  with /tokens POST). POSTs a webbug create, then GETs /c/{id} twice
  from the same CF-Connecting-IP. Asserts: only one notification fires
  (capturingSender callCount == 1), both events recorded (CountByToken
  == 2), one event marked NotifySent + one NotifyDeduped, dedup INCR
  bumped the Redis counter to "2", trigger_count == 2 on the token.

- TestIntegration_DifferentIPsBothNotify: same setup, three different
  IPs each fire their own notification (no cross-IP dedup).

- TestIntegration_DedupTTLExpiry: builds an event.Service with 50ms
  DedupTTL, records two events (second deduped), miniredis.FastForward
  past TTL, third record notifies again — proves the SetNX TTL is the
  authoritative window boundary.

- TestIntegration_RetentionLoopPrunes: inserts 7 events, runs
  RunRetentionLoop with limit=3, asserts the table converges to 3
  rows (newest kept) and the loop exits cleanly on context cancel.

The capturingSender is a notify.Sender impl; this lets us assert
on whether the dispatch goroutine actually called Send() without
mocking the HTTP layer of the real telegram/webhook senders.
2026-05-14 00:32:28 -04:00
..
admin fix(canary-phase0): address audit findings before phase rollup 2026-05-10 05:37:32 -04:00
config feat(canary): wire event + notify into runtime + create-tier rate limits 2026-05-14 00:31:24 -04:00
core fix(canary): replace //nolint pragmas with explicit error handling 2026-05-13 13:28:44 -04:00
event test(canary): testcontainers integration test for trigger + dedup + retention 2026-05-14 00:32:28 -04:00
health fix(canary): replace //nolint pragmas with explicit error handling 2026-05-13 13:28:44 -04:00
middleware feat(canary): turnstile verifier + middleware 2026-05-13 15:08:37 -04:00
notify feat(canary): event + notify domain — contracts, senders, services 2026-05-14 00:30:42 -04:00
server fix(canary-phase1): clear all post-phase-1 audit observations + header normalization 2026-05-10 06:15:26 -04:00
testutil fix(canary): clear pre-audit lint debt + migrate golangci config to v2 2026-05-12 02:49:56 -04:00
token refactor(canary): consolidate realIP into middleware across 5 generators 2026-05-14 00:31:49 -04:00
turnstile feat(canary): turnstile verifier + middleware 2026-05-13 15:08:37 -04:00