newTestRefresher creates a Refresher backed by mock provider/token resolvers. The provider recognises any origin, resolves branches to a canned PR, and returns a canned PRStatus.
(t *testing.T, clk quartz.Clock, opts ...testRefresherOpt)
| 47 | // provider/token resolvers. The provider recognises any origin, |
| 48 | // resolves branches to a canned PR, and returns a canned PRStatus. |
| 49 | func newTestRefresher(t *testing.T, clk quartz.Clock, opts ...testRefresherOpt) *gitsync.Refresher { |
| 50 | t.Helper() |
| 51 | |
| 52 | cfg := testRefresherCfg{ |
| 53 | resolveBranchPR: func(context.Context, string, gitprovider.BranchRef) (*gitprovider.PRRef, error) { |
| 54 | return &gitprovider.PRRef{Owner: "o", Repo: "r", Number: 1}, nil |
| 55 | }, |
| 56 | fetchPRStatus: func(context.Context, string, gitprovider.PRRef) (*gitprovider.PRStatus, error) { |
| 57 | return &gitprovider.PRStatus{ |
| 58 | State: gitprovider.PRStateOpen, |
| 59 | DiffStats: gitprovider.DiffStats{ |
| 60 | Additions: 10, |
| 61 | Deletions: 3, |
| 62 | ChangedFiles: 2, |
| 63 | }, |
| 64 | }, nil |
| 65 | }, |
| 66 | } |
| 67 | for _, o := range opts { |
| 68 | o(&cfg) |
| 69 | } |
| 70 | |
| 71 | prov := &mockProvider{ |
| 72 | parseRepositoryOrigin: func(string) (string, string, string, bool) { |
| 73 | return "owner", "repo", "https://github.com/owner/repo", true |
| 74 | }, |
| 75 | parsePullRequestURL: func(raw string) (gitprovider.PRRef, bool) { |
| 76 | return gitprovider.PRRef{Owner: "owner", Repo: "repo", Number: 1}, raw != "" |
| 77 | }, |
| 78 | resolveBranchPR: cfg.resolveBranchPR, |
| 79 | fetchPullRequestStatus: cfg.fetchPRStatus, |
| 80 | buildPullRequestURL: func(ref gitprovider.PRRef) string { |
| 81 | return fmt.Sprintf("https://github.com/%s/%s/pull/%d", ref.Owner, ref.Repo, ref.Number) |
| 82 | }, |
| 83 | } |
| 84 | |
| 85 | providers := func(context.Context, string) gitprovider.Provider { return prov } |
| 86 | tokens := func(context.Context, uuid.UUID, string) (*string, error) { |
| 87 | return ptr.Ref("tok"), nil |
| 88 | } |
| 89 | |
| 90 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}) |
| 91 | return gitsync.NewRefresher(providers, tokens, logger, clk, cfg.refresherOpts...) |
| 92 | } |
| 93 | |
| 94 | // makeAcquiredRowWithBranch returns an AcquireStaleChatDiffStatusesRow with |
| 95 | // the given branch and a non-empty origin so the Refresher goes through the |
no test coverage detected