| 283 | } |
| 284 | |
| 285 | func 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 | |
| 326 | func TestRefresher_EmptyToken(t *testing.T) { |
| 327 | t.Parallel() |