@@ -1301,21 +1301,25 @@ func TestCommitAndPush(t *testing.T) {
13011301 push bool
13021302 wantErr bool
13031303 expectedErrMsg string
1304+ check func (t * testing.T , repo gitrepo.Repository )
13041305 }{
13051306 {
13061307 name : "Push flag and Commit flag are not specified" ,
13071308 setupMockRepo : func (t * testing.T ) gitrepo.Repository {
1308- repoDir := newTestGitRepoWithCommit (t , "" )
1309- repo , err := gitrepo .NewRepository (& gitrepo.RepositoryOptions {Dir : repoDir })
1310- if err != nil {
1311- t .Fatalf ("Failed to create test repo: %v" , err )
1309+ return & MockRepository {
1310+ Dir : t .TempDir (),
13121311 }
1313- return repo
13141312 },
13151313 setupMockClient : func (t * testing.T ) GitHubClient {
13161314 return nil
13171315 },
13181316 prType : "generate" ,
1317+ check : func (t * testing.T , repo gitrepo.Repository ) {
1318+ mockRepo := repo .(* MockRepository )
1319+ if mockRepo .PushCalls != 0 {
1320+ t .Errorf ("Push was called %d times, expected 0" , mockRepo .PushCalls )
1321+ }
1322+ },
13191323 },
13201324 {
13211325 name : "create a commit" ,
@@ -1339,6 +1343,12 @@ func TestCommitAndPush(t *testing.T) {
13391343 },
13401344 prType : "generate" ,
13411345 commit : true ,
1346+ check : func (t * testing.T , repo gitrepo.Repository ) {
1347+ mockRepo := repo .(* MockRepository )
1348+ if mockRepo .PushCalls != 0 {
1349+ t .Errorf ("Push was called %d times, expected 0" , mockRepo .PushCalls )
1350+ }
1351+ },
13421352 },
13431353 {
13441354 name : "create a generate pull request" ,
@@ -1635,6 +1645,10 @@ func TestCommitAndPush(t *testing.T) {
16351645 t .Errorf ("%s: commitAndPush() returned unexpected error: %v" , test .name , err )
16361646 return
16371647 }
1648+
1649+ if test .check != nil {
1650+ test .check (t , repo )
1651+ }
16381652 })
16391653 }
16401654}
@@ -1651,7 +1665,7 @@ func TestWritePRBody(t *testing.T) {
16511665 repo : & MockRepository {
16521666 Dir : t .TempDir (),
16531667 RemotesValue : []* gitrepo.Remote {
1654- & gitrepo. Remote {
1668+ {
16551669 Name : "origin" ,
16561670 URLs : []string {"https://github.com/googleapis/librarian.git" },
16571671 },
@@ -1669,7 +1683,7 @@ func TestWritePRBody(t *testing.T) {
16691683 repo : & MockRepository {
16701684 Dir : t .TempDir (),
16711685 RemotesValue : []* gitrepo.Remote {
1672- & gitrepo. Remote {
1686+ {
16731687 Name : "not-origin" ,
16741688 URLs : []string {"https://github.com/googleapis/librarian.git" },
16751689 },
@@ -1685,7 +1699,7 @@ func TestWritePRBody(t *testing.T) {
16851699 repo : & MockRepository {
16861700 Dir : t .TempDir (),
16871701 RemotesValue : []* gitrepo.Remote {
1688- & gitrepo. Remote {
1702+ {
16891703 Name : "origin" ,
16901704 URLs : []string {"https://github.com/googleapis/librarian.git" },
16911705 },
@@ -1702,7 +1716,7 @@ func TestWritePRBody(t *testing.T) {
17021716 Dir : t .TempDir (),
17031717 AddAllStatus : make (git.Status ),
17041718 RemotesValue : []* gitrepo.Remote {
1705- & gitrepo. Remote {
1719+ {
17061720 Name : "origin" ,
17071721 URLs : []string {"https://github.com/googleapis/librarian.git" },
17081722 },
0 commit comments