@@ -385,100 +385,3 @@ func TestCreatePullRequest(t *testing.T) {
385385 })
386386 }
387387}
388-
389- func TestEnsureBranchPushed (t * testing.T ) {
390- originalRunGitCommand := runGitCommand
391- t .Cleanup (func () {
392- runGitCommand = originalRunGitCommand
393- })
394-
395- tests := []struct {
396- name string
397- git * stubGitClient
398- runGit func (args ... string ) (string , error )
399- wantErr bool
400- wantErrSubstr string
401- wantCalls [][]string
402- }{
403- {
404- name : "pushes tracked branch with git push" ,
405- git : & stubGitClient {branch : "feature/test" },
406- runGit : func (args ... string ) (string , error ) {
407- return "" , nil
408- },
409- wantCalls : [][]string {
410- {"rev-parse" , "--abbrev-ref" , "--symbolic-full-name" , "@{u}" },
411- {"push" },
412- },
413- },
414- {
415- name : "pushes untracked branch to origin with upstream" ,
416- git : & stubGitClient {branch : "feature/test" },
417- runGit : func (args ... string ) (string , error ) {
418- if reflect .DeepEqual (args , []string {"rev-parse" , "--abbrev-ref" , "--symbolic-full-name" , "@{u}" }) {
419- return "" , errors .New ("no upstream" )
420- }
421- return "" , nil
422- },
423- wantCalls : [][]string {
424- {"rev-parse" , "--abbrev-ref" , "--symbolic-full-name" , "@{u}" },
425- {"push" , "-u" , "origin" , "feature/test" },
426- },
427- },
428- {
429- name : "fails when push errors" ,
430- git : & stubGitClient {branch : "feature/test" },
431- runGit : func (args ... string ) (string , error ) {
432- if reflect .DeepEqual (args , []string {"push" }) {
433- return "" , errors .New ("push failed" )
434- }
435- return "" , nil
436- },
437- wantErr : true ,
438- wantErrSubstr : "pushing current branch" ,
439- wantCalls : [][]string {
440- {"rev-parse" , "--abbrev-ref" , "--symbolic-full-name" , "@{u}" },
441- {"push" },
442- },
443- },
444- {
445- name : "fails when branch is unknown for upstream setup" ,
446- git : & stubGitClient {branch : "" },
447- runGit : func (args ... string ) (string , error ) {
448- if reflect .DeepEqual (args , []string {"rev-parse" , "--abbrev-ref" , "--symbolic-full-name" , "@{u}" }) {
449- return "" , errors .New ("no upstream" )
450- }
451- return "" , nil
452- },
453- wantErr : true ,
454- wantErrSubstr : "unable to determine current branch" ,
455- wantCalls : [][]string {
456- {"rev-parse" , "--abbrev-ref" , "--symbolic-full-name" , "@{u}" },
457- },
458- },
459- }
460-
461- for _ , tt := range tests {
462- t .Run (tt .name , func (t * testing.T ) {
463- var gotCalls [][]string
464- runGitCommand = func (args ... string ) (string , error ) {
465- gotCalls = append (gotCalls , append ([]string (nil ), args ... ))
466- return tt .runGit (args ... )
467- }
468-
469- err := EnsureBranchPushed (tt .git )
470-
471- if (err != nil ) != tt .wantErr {
472- t .Fatalf ("EnsureBranchPushed() error = %v, wantErr %v" , err , tt .wantErr )
473- }
474-
475- if tt .wantErr && tt .wantErrSubstr != "" && (err == nil || ! strings .Contains (err .Error (), tt .wantErrSubstr )) {
476- t .Fatalf ("EnsureBranchPushed() error = %v, want substring %q" , err , tt .wantErrSubstr )
477- }
478-
479- if ! reflect .DeepEqual (gotCalls , tt .wantCalls ) {
480- t .Fatalf ("EnsureBranchPushed() calls = %v, want %v" , gotCalls , tt .wantCalls )
481- }
482- })
483- }
484- }
0 commit comments