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

Function TestRecordInterceptionEnded

coderd/aibridgedserver/aibridgedserver_test.go:980–1035  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

978}
979
980func TestRecordInterceptionEnded(t *testing.T) {
981 t.Parallel()
982
983 testRecordMethod(t,
984 func(srv *aibridgedserver.Server, ctx context.Context, req *proto.RecordInterceptionEndedRequest) (*proto.RecordInterceptionEndedResponse, error) {
985 return srv.RecordInterceptionEnded(ctx, req)
986 },
987 []testRecordMethodCase[*proto.RecordInterceptionEndedRequest]{
988 {
989 name: "ok",
990 request: &proto.RecordInterceptionEndedRequest{
991 Id: uuid.UUID{1}.String(),
992 EndedAt: timestamppb.Now(),
993 CredentialHint: "sk-a...efgh",
994 },
995 setupMocks: func(t *testing.T, db *dbmock.MockStore, req *proto.RecordInterceptionEndedRequest) {
996 interceptionID, err := uuid.Parse(req.GetId())
997 assert.NoError(t, err, "parse interception UUID")
998
999 db.EXPECT().UpdateAIBridgeInterceptionEnded(gomock.Any(), database.UpdateAIBridgeInterceptionEndedParams{
1000 ID: interceptionID,
1001 EndedAt: req.EndedAt.AsTime(),
1002 CredentialHint: req.CredentialHint,
1003 }).Return(database.AIBridgeInterception{
1004 ID: interceptionID,
1005 InitiatorID: uuid.UUID{2},
1006 Provider: "prov",
1007 Model: "mod",
1008 StartedAt: time.Now(),
1009 EndedAt: sql.NullTime{Time: req.EndedAt.AsTime(), Valid: true},
1010 CredentialHint: req.CredentialHint,
1011 }, nil)
1012 },
1013 },
1014 {
1015 name: "bad_uuid_error",
1016 request: &proto.RecordInterceptionEndedRequest{
1017 Id: "this-is-not-uuid",
1018 },
1019 setupMocks: func(t *testing.T, db *dbmock.MockStore, req *proto.RecordInterceptionEndedRequest) {},
1020 expectedErr: "invalid interception ID",
1021 },
1022 {
1023 name: "database_error",
1024 request: &proto.RecordInterceptionEndedRequest{
1025 Id: uuid.UUID{1}.String(),
1026 EndedAt: timestamppb.Now(),
1027 },
1028 setupMocks: func(t *testing.T, db *dbmock.MockStore, req *proto.RecordInterceptionEndedRequest) {
1029 db.EXPECT().UpdateAIBridgeInterceptionEnded(gomock.Any(), gomock.Any()).Return(database.AIBridgeInterception{}, sql.ErrConnDone)
1030 },
1031 expectedErr: "end interception: " + sql.ErrConnDone.Error(),
1032 },
1033 },
1034 )
1035}
1036
1037func TestRecordTokenUsage(t *testing.T) {

Callers

nothing calls this directly

Calls 8

testRecordMethodFunction · 0.85
ParseMethod · 0.65
StringMethod · 0.45
GetIdMethod · 0.45
EXPECTMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected