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

Function TestRefresher_TokenResolutionFails

coderd/x/gitsync/gitsync_test.go:285–324  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

283}
284
285func TestRefresher_TokenResolutionFails(t *testing.T) {
286 t.Parallel()
287
288 var fetchCalled atomic.Bool
289 mp := &mockProvider{
290 fetchPullRequestStatus: func(_ context.Context, _ string, _ gitprovider.PRRef) (*gitprovider.PRStatus, error) {
291 fetchCalled.Store(true)
292 return nil, errors.New("should not be called")
293 },
294 parsePullRequestURL: func(_ string) (gitprovider.PRRef, bool) {
295 return gitprovider.PRRef{Owner: "org", Repo: "repo", Number: 1}, true
296 },
297 }
298
299 providers := func(_ context.Context, _ string) gitprovider.Provider { return mp }
300 tokens := func(_ context.Context, _ uuid.UUID, _ string) (*string, error) {
301 return nil, errors.New("token lookup failed")
302 }
303
304 r := gitsync.NewRefresher(providers, tokens, slogtest.Make(t, nil), quartz.NewReal())
305
306 row := database.ChatDiffStatus{
307 ChatID: uuid.New(),
308 Url: sql.NullString{String: "https://github.com/org/repo/pull/1", Valid: true},
309 GitRemoteOrigin: "https://github.com/org/repo",
310 GitBranch: "feature",
311 }
312
313 ownerID := uuid.New()
314 results, err := r.Refresh(context.Background(), []gitsync.RefreshRequest{
315 {Row: row, OwnerID: ownerID},
316 })
317 require.NoError(t, err)
318 require.Len(t, results, 1)
319 res := results[0]
320
321 assert.Nil(t, res.Params)
322 require.Error(t, res.Error)
323 assert.False(t, fetchCalled.Load(), "FetchPullRequestStatus should not be called when token resolution fails")
324}
325
326func TestRefresher_EmptyToken(t *testing.T) {
327 t.Parallel()

Callers

nothing calls this directly

Calls 7

RefreshMethod · 0.95
NewRefresherFunction · 0.92
NewMethod · 0.65
StoreMethod · 0.45
LenMethod · 0.45
ErrorMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected