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

Function TestRefresher_BranchResolvesToPR

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

Source from the content-addressed store, hash-verified

167}
168
169func TestRefresher_BranchResolvesToPR(t *testing.T) {
170 t.Parallel()
171
172 mp := &mockProvider{
173 parseRepositoryOrigin: func(_ string) (string, string, string, bool) {
174 return "org", "repo", "https://github.com/org/repo", true
175 },
176 resolveBranchPR: func(_ context.Context, _ string, _ gitprovider.BranchRef) (*gitprovider.PRRef, error) {
177 return &gitprovider.PRRef{Owner: "org", Repo: "repo", Number: 7}, nil
178 },
179 fetchPullRequestStatus: func(_ context.Context, _ string, _ gitprovider.PRRef) (*gitprovider.PRStatus, error) {
180 return &gitprovider.PRStatus{State: gitprovider.PRStateOpen}, nil
181 },
182 buildPullRequestURL: func(_ gitprovider.PRRef) string {
183 return "https://github.com/org/repo/pull/7"
184 },
185 }
186
187 providers := func(_ context.Context, _ string) gitprovider.Provider { return mp }
188 tokens := func(_ context.Context, _ uuid.UUID, _ string) (*string, error) {
189 return ptr.Ref("test-token"), nil
190 }
191
192 r := gitsync.NewRefresher(providers, tokens, slogtest.Make(t, nil), quartz.NewReal())
193
194 row := database.ChatDiffStatus{
195 ChatID: uuid.New(),
196 Url: sql.NullString{},
197 GitRemoteOrigin: "https://github.com/org/repo",
198 GitBranch: "feature",
199 }
200
201 ownerID := uuid.New()
202 results, err := r.Refresh(context.Background(), []gitsync.RefreshRequest{
203 {Row: row, OwnerID: ownerID},
204 })
205 require.NoError(t, err)
206 require.Len(t, results, 1)
207 res := results[0]
208
209 require.NoError(t, res.Error)
210 require.NotNil(t, res.Params)
211
212 assert.Contains(t, res.Params.Url.String, "pull/7")
213 assert.True(t, res.Params.Url.Valid)
214 assert.Equal(t, "open", res.Params.PullRequestState.String)
215}
216
217func TestRefresher_BranchNoPRYet(t *testing.T) {
218 t.Parallel()

Callers

nothing calls this directly

Calls 7

RefreshMethod · 0.95
RefFunction · 0.92
NewRefresherFunction · 0.92
NewMethod · 0.65
LenMethod · 0.45
ContainsMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected