MCPcopy Index your code
hub / github.com/coder/coder / TestAISeatsHeartbeat

Function TestAISeatsHeartbeat

enterprise/coderd/usage/cron_test.go:87–108  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

85// to verify that the AsUsagePublisher subject has the required
86// ResourceAiSeat.ActionRead permission.
87func 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}

Callers

nothing calls this directly

Calls 10

EXPECTMethod · 0.95
NewMockStoreFunction · 0.92
NewStrictAuthorizerFunction · 0.92
NewFunction · 0.92
AISeatsHeartbeatFunction · 0.92
ContextFunction · 0.92
WrappersMethod · 0.65
GetActiveAISeatCountMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected