tests: migrate assertions to testify's assert/require

Replaces raw t.Error/t.Errorf/t.Fatal/t.Fatalf across every test file
that has any (domains/accounts, domains/authentication,
domains/raw_events, domains/amazon, domains/reports x2) with testify's
assert (non-halting) / require (halting) equivalents. The three
Example-based tests (server/ui/svg, server/ui/charts) have no
*testing.T at all - nothing to convert there.

require.Eventually replaces several hand-rolled polling loops in
domains/amazon/mock_test.go. Its condition function runs on a separate
goroutine (confirmed in testify's source), so calling require.* from
inside one - which two of the new Eventually calls initially did, via
the isProcessed helper - is unsafe per Go's testing rules (t.FailNow
must only be called from the test's own goroutine). Fixed by splitting
a *testing.T-free queryIsProcessed(ctx, pool, shopID, eventID) out of
isProcessed for use inside those closures specifically.

github.com/stretchr/testify promoted from an indirect to a direct
dependency (go.mod only - it was already present transitively, so
go.sum is unchanged).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XEDaCB7C2NEBgyvqEtZuxY
This commit is contained in:
2026-08-19 23:20:15 -06:00
co-authored by Claude Sonnet 5
parent 6b9e45a1ab
commit 7cbdc6a9e2
8 changed files with 230 additions and 359 deletions
+13 -28
View File
@@ -7,6 +7,8 @@ import (
"time"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"ruben/inventory2/domains/raw_events"
"ruben/inventory2/internal/testdb"
@@ -39,33 +41,20 @@ func TestSaveAndLoadEventsForStore(t *testing.T) {
Payload: json.RawMessage(`{"n":2}`),
}
if err := store.Save(ctx, &older); err != nil {
t.Fatalf("Save() older event error = %v", err)
}
if err := store.Save(ctx, &newer); err != nil {
t.Fatalf("Save() newer event error = %v", err)
}
require.NoError(t, store.Save(ctx, &older), "Save() older event")
require.NoError(t, store.Save(ctx, &newer), "Save() newer event")
got, err := store.LoadEventsForStore(ctx, platform, storeID)
if err != nil {
t.Fatalf("LoadEventsForStore() error = %v", err)
}
if len(got) != 2 {
t.Fatalf("LoadEventsForStore() returned %d events, want 2: %+v", len(got), got)
}
require.NoError(t, err, "LoadEventsForStore()")
require.Len(t, got, 2, "LoadEventsForStore()")
// ordered event_timestamp DESC - newest first.
if got[0].EventID != "evt-2" || got[1].EventID != "evt-1" {
t.Errorf("LoadEventsForStore() order = [%s, %s], want [evt-2, evt-1]", got[0].EventID, got[1].EventID)
}
assert.Equal(t, "evt-2", got[0].EventID, "LoadEventsForStore()[0]")
assert.Equal(t, "evt-1", got[1].EventID, "LoadEventsForStore()[1]")
var payload struct{ N int }
if err := json.Unmarshal(got[0].Payload, &payload); err != nil {
t.Fatalf("failed to unmarshal LoadEventsForStore()[0].Payload = %s: %v", got[0].Payload, err)
}
if payload.N != 2 {
t.Errorf("LoadEventsForStore()[0].Payload n = %d, want 2", payload.N)
}
require.NoError(t, json.Unmarshal(got[0].Payload, &payload), "unmarshal LoadEventsForStore()[0].Payload")
assert.Equal(t, 2, payload.N, "LoadEventsForStore()[0].Payload n")
}
func TestLoadEventsForStore_NoEvents(t *testing.T) {
@@ -74,10 +63,6 @@ func TestLoadEventsForStore_NoEvents(t *testing.T) {
ctx := context.Background()
got, err := store.LoadEventsForStore(ctx, "test-platform", "no-such-store-"+uuid.NewString())
if err != nil {
t.Fatalf("LoadEventsForStore() error = %v", err)
}
if len(got) != 0 {
t.Fatalf("LoadEventsForStore() = %+v, want empty", got)
}
require.NoError(t, err, "LoadEventsForStore()")
assert.Empty(t, got, "LoadEventsForStore()")
}