@@ -1293,15 +1293,16 @@ func TestCompileRegexps(t *testing.T) {
12931293
12941294func TestCommitAndPush (t * testing.T ) {
12951295 for _ , test := range []struct {
1296- name string
1297- setupMockRepo func (t * testing.T ) gitrepo.Repository
1298- setupMockClient func (t * testing.T ) GitHubClient
1299- state * config.LibrarianState
1300- prType string
1301- commit bool
1302- push bool
1303- wantErr bool
1304- expectedErrMsg string
1296+ name string
1297+ setupMockRepo func (t * testing.T ) gitrepo.Repository
1298+ setupMockClient func (t * testing.T ) GitHubClient
1299+ state * config.LibrarianState
1300+ prType string
1301+ failedGenerations int
1302+ commit bool
1303+ push bool
1304+ wantErr bool
1305+ expectedErrMsg string
13051306 }{
13061307 {
13071308 name : "Push flag and Commit flag are not specified" ,
@@ -1576,19 +1577,48 @@ func TestCommitAndPush(t *testing.T) {
15761577 prType : "generate" ,
15771578 push : true ,
15781579 },
1580+ {
1581+ name : "create_a_comment_on_generation_pr_error" ,
1582+ setupMockRepo : func (t * testing.T ) gitrepo.Repository {
1583+ remote := git .NewRemote (memory .NewStorage (), & gogitConfig.RemoteConfig {
1584+ Name : "origin" ,
1585+ URLs : []string {"https://github.com/googleapis/librarian.git" },
1586+ })
1587+ status := make (git.Status )
1588+ status ["file.txt" ] = & git.FileStatus {Worktree : git .Modified }
1589+ return & MockRepository {
1590+ Dir : t .TempDir (),
1591+ AddAllStatus : status ,
1592+ RemotesValue : []* git.Remote {remote },
1593+ }
1594+ },
1595+ setupMockClient : func (t * testing.T ) GitHubClient {
1596+ return & mockGitHubClient {
1597+ createdPR : & github.PullRequestMetadata {Number : 123 , Repo : & github.Repository {Owner : "test-owner" , Name : "test-repo" }},
1598+ createIssueErr : errors .New ("simulate comment creation error" ),
1599+ }
1600+ },
1601+ state : & config.LibrarianState {},
1602+ prType : "generate" ,
1603+ failedGenerations : 1 ,
1604+ push : true ,
1605+ wantErr : true ,
1606+ expectedErrMsg : "failed to add pull request comment" ,
1607+ },
15791608 } {
15801609 t .Run (test .name , func (t * testing.T ) {
15811610 repo := test .setupMockRepo (t )
15821611 client := test .setupMockClient (t )
15831612
15841613 commitInfo := & commitInfo {
1585- commit : test .commit ,
1586- commitMessage : "" ,
1587- ghClient : client ,
1588- prType : test .prType ,
1589- push : test .push ,
1590- repo : repo ,
1591- state : test .state ,
1614+ commit : test .commit ,
1615+ commitMessage : "" ,
1616+ ghClient : client ,
1617+ prType : test .prType ,
1618+ push : test .push ,
1619+ repo : repo ,
1620+ state : test .state ,
1621+ failedGenerations : test .failedGenerations ,
15921622 }
15931623
15941624 err := commitAndPush (context .Background (), commitInfo )
0 commit comments