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

Function testRecordMethod

coderd/aibridgedserver/aibridgedserver_test.go:1388–1421  ·  view source on GitHub ↗

testRecordMethod is a helper that abstracts the common testing pattern for all Record* methods.

(
	t *testing.T,
	callMethod func(srv *aibridgedserver.Server, ctx context.Context, req Req) (Resp, error),
	cases []testRecordMethodCase[Req],
)

Source from the content-addressed store, hash-verified

1386
1387// testRecordMethod is a helper that abstracts the common testing pattern for all Record* methods.
1388func testRecordMethod[Req any, Resp any](
1389 t *testing.T,
1390 callMethod func(srv *aibridgedserver.Server, ctx context.Context, req Req) (Resp, error),
1391 cases []testRecordMethodCase[Req],
1392) {
1393 t.Helper()
1394
1395 for _, tc := range cases {
1396 t.Run(tc.name, func(t *testing.T) {
1397 t.Parallel()
1398
1399 ctrl := gomock.NewController(t)
1400 db := dbmock.NewMockStore(ctrl)
1401 logger := testutil.Logger(t)
1402
1403 if tc.setupMocks != nil {
1404 tc.setupMocks(t, db, tc.request)
1405 }
1406
1407 ctx := testutil.Context(t, testutil.WaitLong)
1408 srv, err := aibridgedserver.NewServer(ctx, db, logger, "/", codersdk.AIBridgeConfig{}, nil, requiredExperiments, agplaiseats.Noop{})
1409 require.NoError(t, err)
1410
1411 resp, err := callMethod(srv, ctx, tc.request)
1412 if tc.expectedErr != "" {
1413 require.Error(t, err, "Expected error for test case: %s", tc.name)
1414 require.Contains(t, err.Error(), tc.expectedErr)
1415 } else {
1416 require.NoError(t, err, "Unexpected error for test case: %s", tc.name)
1417 require.NotNil(t, resp)
1418 }
1419 })
1420 }
1421}
1422
1423// Helper functions.
1424func mustMarshalAny(t *testing.T, msg protobufproto.Message) *anypb.Any {

Callers 6

TestRecordInterceptionFunction · 0.85
TestRecordTokenUsageFunction · 0.85
TestRecordPromptUsageFunction · 0.85
TestRecordToolUsageFunction · 0.85
TestRecordModelThoughtFunction · 0.85

Calls 8

NewMockStoreFunction · 0.92
LoggerFunction · 0.92
ContextFunction · 0.92
NewServerFunction · 0.92
HelperMethod · 0.65
RunMethod · 0.65
ErrorMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected