MCPcopy
hub / github.com/cli/cli / Test_SyncRun

Function Test_SyncRun

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

Source from the content-addressed store, hash-verified

101}
102
103func Test_SyncRun(t *testing.T) {
104 tests := []struct {
105 name string
106 tty bool
107 opts *SyncOptions
108 remotes []*context.Remote
109 httpStubs func(*httpmock.Registry)
110 gitStubs func(*mockGitClient)
111 wantStdout string
112 wantErr bool
113 errMsg string
114 }{
115 {
116 name: "sync local repo with parent - tty",
117 tty: true,
118 opts: &SyncOptions{},
119 httpStubs: func(reg *httpmock.Registry) {
120 reg.Register(
121 httpmock.GraphQL(`query RepositoryInfo\b`),
122 httpmock.StringResponse(`{"data":{"repository":{"defaultBranchRef":{"name": "trunk"}}}}`))
123 },
124 gitStubs: func(mgc *mockGitClient) {
125 mgc.On("Fetch", "origin", "refs/heads/trunk").Return(nil).Once()
126 mgc.On("HasLocalBranch", "trunk").Return(true).Once()
127 mgc.On("IsAncestor", "trunk", "FETCH_HEAD").Return(true, nil).Once()
128 mgc.On("CurrentBranch").Return("trunk", nil).Once()
129 mgc.On("IsDirty").Return(false, nil).Once()
130 mgc.On("MergeFastForward", "FETCH_HEAD").Return(nil).Once()
131 },
132 wantStdout: "✓ Synced the \"trunk\" branch from \"OWNER/REPO\" to local repository\n",
133 },
134 {
135 name: "sync local repo with parent - notty",
136 tty: false,
137 opts: &SyncOptions{
138 Branch: "trunk",
139 },
140 gitStubs: func(mgc *mockGitClient) {
141 mgc.On("Fetch", "origin", "refs/heads/trunk").Return(nil).Once()
142 mgc.On("HasLocalBranch", "trunk").Return(true).Once()
143 mgc.On("IsAncestor", "trunk", "FETCH_HEAD").Return(true, nil).Once()
144 mgc.On("CurrentBranch").Return("trunk", nil).Once()
145 mgc.On("IsDirty").Return(false, nil).Once()
146 mgc.On("MergeFastForward", "FETCH_HEAD").Return(nil).Once()
147 },
148 wantStdout: "",
149 },
150 {
151 name: "sync local repo with specified source repo",
152 tty: true,
153 opts: &SyncOptions{
154 Branch: "trunk",
155 SrcArg: "OWNER2/REPO2",
156 },
157 gitStubs: func(mgc *mockGitClient) {
158 mgc.On("Fetch", "upstream", "refs/heads/trunk").Return(nil).Once()
159 mgc.On("HasLocalBranch", "trunk").Return(true).Once()
160 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