(t *testing.T)
| 32 | t.Cleanup(func() { analytics.SetDefault(nil) }) |
| 33 | return fake |
| 34 | } |
| 35 | |
| 36 | func TestLogClientQueryReceivedEmitsQueryInitiated(t *testing.T) { |
| 37 | fake := installFakeQueryTracker(t) |
| 38 | c := &clientConn{orgID: "acme", username: "root", teamID: 42, applicationName: "psql", ctx: context.Background()} |
| 39 | |
| 40 | c.logClientQueryReceived(context.Background(), "simple", "SELECT 1") |
| 41 | |
| 42 | if len(fake.events) != 1 { |
| 43 | t.Fatalf("expected 1 event, got %d", len(fake.events)) |
| 44 | } |
| 45 | e := fake.events[0] |
| 46 | if e.event != "query_initiated" { |
| 47 | t.Errorf("event = %q, want query_initiated", e.event) |
| 48 | } |
| 49 | if e.orgID != "acme" { |
| 50 | t.Errorf("orgID = %q, want acme", e.orgID) |
| 51 | } |
| 52 | if e.props["user"] != "root" { |
| 53 | t.Errorf("user = %v, want root", e.props["user"]) |
| 54 | } |
| 55 | if e.props["team_id"] != int64(42) { |
| 56 | t.Errorf("team_id = %v, want 42", e.props["team_id"]) |
nothing calls this directly
no test coverage detected