| 355 | } |
| 356 | |
| 357 | func TestRefresher_ProviderFetchFails(t *testing.T) { |
| 358 | t.Parallel() |
| 359 | |
| 360 | mp := &mockProvider{ |
| 361 | parsePullRequestURL: func(_ string) (gitprovider.PRRef, bool) { |
| 362 | return gitprovider.PRRef{Owner: "org", Repo: "repo", Number: 42}, true |
| 363 | }, |
| 364 | fetchPullRequestStatus: func(_ context.Context, _ string, _ gitprovider.PRRef) (*gitprovider.PRStatus, error) { |
| 365 | return nil, errors.New("api error") |
| 366 | }, |
| 367 | } |
| 368 | |
| 369 | providers := func(_ context.Context, _ string) gitprovider.Provider { return mp } |
| 370 | tokens := func(_ context.Context, _ uuid.UUID, _ string) (*string, error) { |
| 371 | return ptr.Ref("test-token"), nil |
| 372 | } |
| 373 | |
| 374 | r := gitsync.NewRefresher(providers, tokens, slogtest.Make(t, nil), quartz.NewReal()) |
| 375 | |
| 376 | row := database.ChatDiffStatus{ |
| 377 | ChatID: uuid.New(), |
| 378 | Url: sql.NullString{String: "https://github.com/org/repo/pull/42", Valid: true}, |
| 379 | GitRemoteOrigin: "https://github.com/org/repo", |
| 380 | GitBranch: "feature", |
| 381 | } |
| 382 | |
| 383 | ownerID := uuid.New() |
| 384 | results, err := r.Refresh(context.Background(), []gitsync.RefreshRequest{ |
| 385 | {Row: row, OwnerID: ownerID}, |
| 386 | }) |
| 387 | require.NoError(t, err) |
| 388 | require.Len(t, results, 1) |
| 389 | res := results[0] |
| 390 | |
| 391 | assert.Nil(t, res.Params) |
| 392 | require.Error(t, res.Error) |
| 393 | assert.Contains(t, res.Error.Error(), "api error") |
| 394 | } |
| 395 | |
| 396 | func TestRefresher_PRURLParseFailure(t *testing.T) { |
| 397 | t.Parallel() |