(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestGetBillableUsageAboveThreshold(t *testing.T) { |
| 19 | chCfg := containers.ClickHouse(t) |
| 20 | dsn := chCfg.DSN |
| 21 | |
| 22 | // Create ClickHouse client using the clickhouse package |
| 23 | client, err := clickhouse.New(clickhouse.Config{ |
| 24 | URL: dsn, |
| 25 | }) |
| 26 | require.NoError(t, err) |
| 27 | t.Cleanup(func() { require.NoError(t, client.Close()) }) |
| 28 | |
| 29 | err = client.Ping(context.Background()) |
| 30 | require.NoError(t, err) |
| 31 | |
| 32 | // Also get a direct connection for inserting test data |
| 33 | opts, err := ch.ParseDSN(dsn) |
| 34 | require.NoError(t, err) |
| 35 | |
| 36 | conn, err := ch.Open(opts) |
| 37 | require.NoError(t, err) |
| 38 | t.Cleanup(func() { require.NoError(t, conn.Close()) }) |
| 39 | |
| 40 | ctx := context.Background() |
| 41 | |
| 42 | // Use current year/month for testing |
| 43 | now := time.Now() |
| 44 | year := now.Year() |
| 45 | month := int(now.Month()) |
| 46 | |
| 47 | t.Run("multiple workspaces with both verifications and ratelimits", func(t *testing.T) { |
| 48 | // Create test workspaces |
| 49 | workspace1 := uid.New(uid.WorkspacePrefix) |
| 50 | workspace2 := uid.New(uid.WorkspacePrefix) |
| 51 | workspace3 := uid.New(uid.WorkspacePrefix) |
| 52 | |
| 53 | // Insert verifications |
| 54 | // Workspace 1: 100 VALID verifications |
| 55 | verifications := createVerifications(workspace1, 100, now, "VALID") |
| 56 | verifications = append(verifications, createVerifications(workspace2, 50, now, "VALID")...) |
| 57 | verifications = append(verifications, createVerifications(workspace3, 200, now, "VALID")...) |
| 58 | |
| 59 | insertVerifications(t, ctx, conn, verifications) |
| 60 | |
| 61 | // Insert ratelimits |
| 62 | // Workspace 1: 30 passed ratelimits |
| 63 | ratelimits := createRatelimits(workspace1, 30, now, true) |
| 64 | ratelimits = append(ratelimits, createRatelimits(workspace2, 70, now, true)...) |
| 65 | // No ratelimits for workspace3 |
| 66 | |
| 67 | insertRatelimits(t, ctx, conn, ratelimits) |
| 68 | |
| 69 | // Wait for materialized views to process |
| 70 | require.EventuallyWithT(t, func(c *assert.CollectT) { |
| 71 | usage, err := client.GetBillableUsageAboveThreshold(ctx, year, month, 0) |
| 72 | require.NoError(c, err) |
| 73 | |
| 74 | // Workspace1: 100 verifications + 30 ratelimits = 130 |
| 75 | assert.Equal(c, int64(130), usage[workspace1], "workspace1 usage mismatch") |
nothing calls this directly
no test coverage detected