MCPcopy Create free account
hub / github.com/cli/cli / Test_SyncRun

Function Test_SyncRun

pkg/cmd/repo/sync/sync_test.go:259–766  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

257}
258
259func Test_SyncRun(t *testing.T) {
260 tests := []struct {
261 name string
262 tty bool
263 opts *SyncOptions
264 remotes []*context.Remote
265 httpStubs func(*httpmock.Registry)
266 gitStubs func(*mockGitClient)
267 wantStdout string
268 wantErr bool
269 errMsg string
270 }{
271 {
272 name: "sync local repo with parent - tty",
273 tty: true,
274 opts: &SyncOptions{},
275 httpStubs: func(reg *httpmock.Registry) {
276 reg.Register(
277 httpmock.GraphQL(`query RepositoryInfo\b`),
278 httpmock.StringResponse(`{"data":{"repository":{"defaultBranchRef":{"name": "trunk"}}}}`))
279 },
280 gitStubs: func(mgc *mockGitClient) {
281 mgc.On("Fetch", "origin", "refs/heads/trunk").Return(nil).Once()
282 mgc.On("HasLocalBranch", "trunk").Return(true).Once()
283 mgc.On("IsAncestor", "trunk", "FETCH_HEAD").Return(true, nil).Once()
284 mgc.On("CurrentBranch").Return("trunk", nil).Once()
285 mgc.On("IsDirty").Return(false, nil).Once()
286 mgc.On("MergeFastForward", "FETCH_HEAD").Return(nil).Once()
287 },
288 wantStdout: "✓ Synced the \"trunk\" branch from \"OWNER/REPO\" to local repository\n",
289 },
290 {
291 name: "sync local repo with parent - notty",
292 tty: false,
293 opts: &SyncOptions{
294 Branch: "trunk",
295 },
296 gitStubs: func(mgc *mockGitClient) {
297 mgc.On("Fetch", "origin", "refs/heads/trunk").Return(nil).Once()
298 mgc.On("HasLocalBranch", "trunk").Return(true).Once()
299 mgc.On("IsAncestor", "trunk", "FETCH_HEAD").Return(true, nil).Once()
300 mgc.On("CurrentBranch").Return("trunk", nil).Once()
301 mgc.On("IsDirty").Return(false, nil).Once()
302 mgc.On("MergeFastForward", "FETCH_HEAD").Return(nil).Once()
303 },
304 wantStdout: "",
305 },
306 {
307 name: "sync local repo with specified source repo",
308 tty: true,
309 opts: &SyncOptions{
310 Branch: "trunk",
311 SrcArg: "OWNER2/REPO2",
312 },
313 gitStubs: func(mgc *mockGitClient) {
314 mgc.On("Fetch", "upstream", "refs/heads/trunk").Return(nil).Once()
315 mgc.On("HasLocalBranch", "trunk").Return(true).Once()
316 mgc.On("IsAncestor", "trunk", "FETCH_HEAD").Return(true, nil).Once()

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
VerifyMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
RESTFunction · 0.92
StatusStringResponseFunction · 0.92
StatusJSONResponseFunction · 0.92
TestFunction · 0.92
FromFullNameFunction · 0.92
newMockGitClientFunction · 0.85
syncRunFunction · 0.85
SetStdinTTYMethod · 0.80

Tested by

no test coverage detected