(t *testing.T)
| 257 | } |
| 258 | |
| 259 | func 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() |
nothing calls this directly
no test coverage detected