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

Function TestRefreshChat_UpsertError

coderd/x/gitsync/worker_test.go:1139–1174  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1137}
1138
1139func TestRefreshChat_UpsertError(t *testing.T) {
1140 t.Parallel()
1141 ctx := testutil.Context(t, testutil.WaitShort)
1142
1143 chatID := uuid.New()
1144 ownerID := uuid.New()
1145
1146 row := database.ChatDiffStatus{
1147 ChatID: chatID,
1148 GitBranch: "feature",
1149 GitRemoteOrigin: "https://github.com/owner/repo",
1150 }
1151
1152 ctrl := gomock.NewController(t)
1153 store := dbmock.NewMockStore(ctrl)
1154
1155 store.EXPECT().UpsertChatDiffStatus(gomock.Any(), gomock.Any()).
1156 Return(database.ChatDiffStatus{}, fmt.Errorf("db write error"))
1157
1158 var publishCalled atomic.Bool
1159 pub := func(_ context.Context, _ uuid.UUID) error {
1160 publishCalled.Store(true)
1161 return nil
1162 }
1163
1164 mClock := quartz.NewMock(t)
1165 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
1166 refresher := newTestRefresher(t, mClock)
1167 worker := gitsync.NewWorker(store, refresher, pub, mClock, logger)
1168
1169 result, err := worker.RefreshChat(ctx, row, ownerID)
1170 require.Error(t, err)
1171 assert.Contains(t, err.Error(), "upsert chat diff status")
1172 assert.Nil(t, result)
1173 assert.False(t, publishCalled.Load(), "publish should not be called when upsert fails")
1174}
1175
1176func TestWorker_NoTokenBackoff(t *testing.T) {
1177 t.Parallel()

Callers

nothing calls this directly

Calls 13

EXPECTMethod · 0.95
RefreshChatMethod · 0.95
ContextFunction · 0.92
NewMockStoreFunction · 0.92
NewWorkerFunction · 0.92
newTestRefresherFunction · 0.85
NewMethod · 0.65
UpsertChatDiffStatusMethod · 0.65
ErrorfMethod · 0.45
StoreMethod · 0.45
ErrorMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected