TestAISeatsHeartbeat checks that AISeatsHeartbeat returns the correct event type and count. It wraps a mock database with dbauthz to verify that the AsUsagePublisher subject has the required ResourceAiSeat.ActionRead permission.
(t *testing.T)
| 85 | // to verify that the AsUsagePublisher subject has the required |
| 86 | // ResourceAiSeat.ActionRead permission. |
| 87 | func TestAISeatsHeartbeat(t *testing.T) { |
| 88 | t.Parallel() |
| 89 | |
| 90 | ctrl := gomock.NewController(t) |
| 91 | db := dbmock.NewMockStore(ctrl) |
| 92 | |
| 93 | db.EXPECT().Wrappers().Return([]string{}).AnyTimes() |
| 94 | db.EXPECT().GetActiveAISeatCount(gomock.Any()).Return(int64(42), nil) |
| 95 | |
| 96 | authz := rbac.NewStrictAuthorizer(prometheus.NewRegistry()) |
| 97 | authzDB := dbauthz.New(db, authz, slogtest.Make(t, nil), coderdtest.AccessControlStorePointer()) |
| 98 | |
| 99 | // AISeatsHeartbeat internally uses AsUsagePublisher, which must |
| 100 | // have ResourceAiSeat.ActionRead to pass the dbauthz check. |
| 101 | fn := usage.AISeatsHeartbeat(authzDB) |
| 102 | event, err := fn(testutil.Context(t, testutil.WaitLong)) |
| 103 | require.NoError(t, err) |
| 104 | |
| 105 | hb, ok := event.(usagetypes.HBAISeats) |
| 106 | require.True(t, ok) |
| 107 | assert.Equal(t, int64(42), hb.Count) |
| 108 | } |
nothing calls this directly
no test coverage detected