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

Function TestWorker_MarkStale_WithChatID

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

Source from the content-addressed store, hash-verified

814}
815
816func TestWorker_MarkStale_WithChatID(t *testing.T) {
817 t.Parallel()
818 ctx := testutil.Context(t, testutil.WaitShort)
819
820 targetChat := uuid.New()
821
822 var mu sync.Mutex
823 var upsertRefCalls []database.UpsertChatDiffStatusReferenceParams
824 var publishedIDs []uuid.UUID
825
826 ctrl := gomock.NewController(t)
827 store := dbmock.NewMockStore(ctrl)
828
829 // GetChatsByWorkspaceIDs should NOT be called when a specific chat ID is provided.
830 store.EXPECT().GetChatsByWorkspaceIDs(gomock.Any(), gomock.Any()).Times(0)
831 store.EXPECT().UpsertChatDiffStatusReference(gomock.Any(), gomock.Any()).DoAndReturn(func(_ context.Context, arg database.UpsertChatDiffStatusReferenceParams) (database.ChatDiffStatus, error) {
832 mu.Lock()
833 upsertRefCalls = append(upsertRefCalls, arg)
834 mu.Unlock()
835 return database.ChatDiffStatus{ChatID: arg.ChatID}, nil
836 }).Times(1)
837
838 pub := func(_ context.Context, chatID uuid.UUID) error {
839 mu.Lock()
840 publishedIDs = append(publishedIDs, chatID)
841 mu.Unlock()
842 return nil
843 }
844
845 mClock := quartz.NewMock(t)
846 now := mClock.Now()
847 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true})
848 refresher := newTestRefresher(t, mClock)
849 worker := gitsync.NewWorker(store, refresher, pub, mClock, logger)
850
851 worker.MarkStale(ctx, gitsync.MarkStaleParams{
852 WorkspaceID: uuid.New(),
853 Branch: "my-branch",
854 Origin: "https://github.com/org/repo",
855 ChatID: targetChat,
856 })
857
858 mu.Lock()
859 defer mu.Unlock()
860
861 require.Len(t, upsertRefCalls, 1)
862 assert.Equal(t, targetChat, upsertRefCalls[0].ChatID)
863 assert.Equal(t, "my-branch", upsertRefCalls[0].GitBranch)
864 assert.Equal(t, "https://github.com/org/repo", upsertRefCalls[0].GitRemoteOrigin)
865 assert.True(t, upsertRefCalls[0].StaleAt.Before(now),
866 "stale_at should be in the past, got %v vs now %v", upsertRefCalls[0].StaleAt, now)
867
868 require.Len(t, publishedIDs, 1)
869 assert.Equal(t, targetChat, publishedIDs[0])
870}
871
872func TestWorker_MarkStale_NilChatID_Broadcasts(t *testing.T) {
873 t.Parallel()

Callers

nothing calls this directly

Calls 13

EXPECTMethod · 0.95
MarkStaleMethod · 0.95
ContextFunction · 0.92
NewMockStoreFunction · 0.92
NewWorkerFunction · 0.92
newTestRefresherFunction · 0.85
NewMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected