@@ -479,16 +479,16 @@ func TestCopyOneLibrary(t *testing.T) {
479479
480480func TestCommitAndPush (t * testing.T ) {
481481 for _ , test := range []struct {
482- name string
483- setupMockRepo func (t * testing.T ) gitrepo.Repository
484- setupMockClient func (t * testing.T ) GitHubClient
485- push bool
486- wantErr bool
487- expectedErrMsg string
488- validatePostTest func ( t * testing. T , repo gitrepo. Repository )
482+ name string
483+ setupMockRepo func (t * testing.T ) gitrepo.Repository
484+ setupMockClient func (t * testing.T ) GitHubClient
485+ commit bool
486+ push bool
487+ wantErr bool
488+ expectedErrMsg string
489489 }{
490490 {
491- name : "Push flag not specified" ,
491+ name : "Push flag and Commit flag are not specified" ,
492492 setupMockRepo : func (t * testing.T ) gitrepo.Repository {
493493 repoDir := newTestGitRepoWithCommit (t , "" )
494494 repo , err := gitrepo .NewRepository (& gitrepo.RepositoryOptions {Dir : repoDir })
@@ -502,14 +502,39 @@ func TestCommitAndPush(t *testing.T) {
502502 },
503503 },
504504 {
505- name : "Happy Path " ,
505+ name : "create a commit " ,
506506 setupMockRepo : func (t * testing.T ) gitrepo.Repository {
507507 remote := git .NewRemote (memory .NewStorage (), & gogitConfig.RemoteConfig {
508508 Name : "origin" ,
509509 URLs : []string {"https://github.com/googleapis/librarian.git" },
510510 })
511+ status := make (git.Status )
512+ status ["file.txt" ] = & git.FileStatus {Worktree : git .Modified }
513+ return & MockRepository {
514+ Dir : t .TempDir (),
515+ AddAllStatus : status ,
516+ RemotesValue : []* git.Remote {remote },
517+ }
518+ },
519+ setupMockClient : func (t * testing.T ) GitHubClient {
520+ return & mockGitHubClient {
521+ createdPR : & github.PullRequestMetadata {Number : 123 , Repo : & github.Repository {Owner : "test-owner" , Name : "test-repo" }},
522+ }
523+ },
524+ commit : true ,
525+ },
526+ {
527+ name : "create a pull request" ,
528+ setupMockRepo : func (t * testing.T ) gitrepo.Repository {
529+ remote := git .NewRemote (memory .NewStorage (), & gogitConfig.RemoteConfig {
530+ Name : "origin" ,
531+ URLs : []string {"https://github.com/googleapis/librarian.git" },
532+ })
533+ status := make (git.Status )
534+ status ["file.txt" ] = & git.FileStatus {Worktree : git .Modified }
511535 return & MockRepository {
512536 Dir : t .TempDir (),
537+ AddAllStatus : status ,
513538 RemotesValue : []* git.Remote {remote },
514539 }
515540 },
@@ -523,8 +548,11 @@ func TestCommitAndPush(t *testing.T) {
523548 {
524549 name : "No GitHub Remote" ,
525550 setupMockRepo : func (t * testing.T ) gitrepo.Repository {
551+ status := make (git.Status )
552+ status ["file.txt" ] = & git.FileStatus {Worktree : git .Modified }
526553 return & MockRepository {
527554 Dir : t .TempDir (),
555+ AddAllStatus : status ,
528556 RemotesValue : []* git.Remote {}, // No remotes
529557 }
530558 },
@@ -675,7 +703,8 @@ func TestCommitAndPush(t *testing.T) {
675703 repo := test .setupMockRepo (t )
676704 client := test .setupMockClient (t )
677705 localConfig := & config.Config {
678- Push : test .push ,
706+ Push : test .push ,
707+ Commit : test .commit ,
679708 }
680709
681710 err := commitAndPush (context .Background (), localConfig , repo , client , "" )
@@ -692,10 +721,6 @@ func TestCommitAndPush(t *testing.T) {
692721 t .Errorf ("%s: commitAndPush() returned unexpected error: %v" , test .name , err )
693722 return
694723 }
695-
696- if test .validatePostTest != nil {
697- test .validatePostTest (t , repo )
698- }
699724 })
700725 }
701726}
0 commit comments