@@ -254,7 +254,7 @@ func TestCloneOrOpenLanguageRepo(t *testing.T) {
254254 }
255255 }()
256256
257- repo , err := cloneOrOpenRepo (workRoot , test .repo , test .ci )
257+ repo , err := cloneOrOpenRepo (workRoot , test .repo , test .ci , "" )
258258 if test .wantErr {
259259 if err == nil {
260260 t .Error ("cloneOrOpenLanguageRepo() expected an error but got nil" )
@@ -302,42 +302,21 @@ func TestCommitAndPush(t *testing.T) {
302302 {
303303 name : "Happy Path" ,
304304 setupMockRepo : func (t * testing.T ) gitrepo.Repository {
305- repoDir := newTestGitRepoWithCommit (t , "" )
306- // Add remote so FetchGitHubRepoFromRemote succeeds.
307- cmd := exec .Command ("git" , "remote" , "add" , "origin" , "https://github.com/test-owner/test-repo.git" )
308- cmd .Dir = repoDir
309- if err := cmd .Run (); err != nil {
310- t .Fatalf ("git remote add: %v" , err )
311- }
312- // Add a file to make the repo dirty, so there's something to commit.
313- if err := os .WriteFile (filepath .Join (repoDir , "new-file.txt" ), []byte ("new content" ), 0644 ); err != nil {
314- t .Fatalf ("WriteFile: %v" , err )
315- }
316- repo , err := gitrepo .NewRepository (& gitrepo.RepositoryOptions {Dir : repoDir })
317- if err != nil {
318- t .Fatalf ("Failed to create test repo: %v" , err )
305+ remote := git .NewRemote (memory .NewStorage (), & gogitConfig.RemoteConfig {
306+ Name : "origin" ,
307+ URLs : []string {"https://github.com/googleapis/librarian.git" },
308+ })
309+ return & MockRepository {
310+ Dir : t .TempDir (),
311+ RemotesValue : []* git.Remote {remote },
319312 }
320- return repo
321313 },
322314 setupMockClient : func (t * testing.T ) GitHubClient {
323315 return & mockGitHubClient {
324316 createdPR : & github.PullRequestMetadata {Number : 123 , Repo : & github.Repository {Owner : "test-owner" , Name : "test-repo" }},
325317 }
326318 },
327319 push : true ,
328- validatePostTest : func (t * testing.T , repo gitrepo.Repository ) {
329- localRepo , ok := repo .(* gitrepo.LocalRepository )
330- if ! ok {
331- t .Fatalf ("Expected *gitrepo.LocalRepository, got %T" , repo )
332- }
333- isClean , err := localRepo .IsClean ()
334- if err != nil {
335- t .Fatalf ("Failed to check repo status: %v" , err )
336- }
337- if ! isClean {
338- t .Errorf ("Expected repository to be clean after commit, but it's dirty" )
339- }
340- },
341320 },
342321 {
343322 name : "No GitHub Remote" ,
@@ -374,6 +353,30 @@ func TestCommitAndPush(t *testing.T) {
374353 wantErr : true ,
375354 expectedErrMsg : "mock add all error" ,
376355 },
356+ {
357+ name : "Create branch error" ,
358+ setupMockRepo : func (t * testing.T ) gitrepo.Repository {
359+ remote := git .NewRemote (memory .NewStorage (), & gogitConfig.RemoteConfig {
360+ Name : "origin" ,
361+ URLs : []string {"https://github.com/googleapis/librarian.git" },
362+ })
363+
364+ status := make (git.Status )
365+ status ["file.txt" ] = & git.FileStatus {Worktree : git .Modified }
366+ return & MockRepository {
367+ Dir : t .TempDir (),
368+ AddAllStatus : status ,
369+ RemotesValue : []* git.Remote {remote },
370+ CreateBranchAndCheckoutError : errors .New ("create branch error" ),
371+ }
372+ },
373+ setupMockClient : func (t * testing.T ) GitHubClient {
374+ return nil
375+ },
376+ push : true ,
377+ wantErr : true ,
378+ expectedErrMsg : "create branch error" ,
379+ },
377380 {
378381 name : "Commit error" ,
379382 setupMockRepo : func (t * testing.T ) gitrepo.Repository {
@@ -398,6 +401,30 @@ func TestCommitAndPush(t *testing.T) {
398401 wantErr : true ,
399402 expectedErrMsg : "commit error" ,
400403 },
404+ {
405+ name : "Push error" ,
406+ setupMockRepo : func (t * testing.T ) gitrepo.Repository {
407+ remote := git .NewRemote (memory .NewStorage (), & gogitConfig.RemoteConfig {
408+ Name : "origin" ,
409+ URLs : []string {"https://github.com/googleapis/librarian.git" },
410+ })
411+
412+ status := make (git.Status )
413+ status ["file.txt" ] = & git.FileStatus {Worktree : git .Modified }
414+ return & MockRepository {
415+ Dir : t .TempDir (),
416+ AddAllStatus : status ,
417+ RemotesValue : []* git.Remote {remote },
418+ PushError : errors .New ("push error" ),
419+ }
420+ },
421+ setupMockClient : func (t * testing.T ) GitHubClient {
422+ return nil
423+ },
424+ push : true ,
425+ wantErr : true ,
426+ expectedErrMsg : "push error" ,
427+ },
401428 {
402429 name : "Create pull request error" ,
403430 setupMockRepo : func (t * testing.T ) gitrepo.Repository {
0 commit comments