@@ -18,7 +18,6 @@ import (
1818 "context"
1919 "errors"
2020 "os"
21- "os/exec"
2221 "path/filepath"
2322 "regexp"
2423 "sort"
@@ -28,7 +27,6 @@ import (
2827 "github.com/google/go-cmp/cmp"
2928 "github.com/googleapis/librarian/internal/config"
3029 "github.com/googleapis/librarian/internal/gitrepo"
31- "gopkg.in/yaml.v3"
3230)
3331
3432func TestRunGenerateCommand (t * testing.T ) {
@@ -453,46 +451,6 @@ func TestNewGenerateRunner(t *testing.T) {
453451 } {
454452 t .Run (test .name , func (t * testing.T ) {
455453 t .Parallel ()
456- // We need to create a fake state and config file for the test to pass.
457- if test .cfg .Repo != "" && ! isURL (test .cfg .Repo ) {
458- stateFile := filepath .Join (test .cfg .Repo , config .LibrarianDir , pipelineStateFile )
459-
460- if err := os .MkdirAll (filepath .Dir (stateFile ), 0755 ); err != nil {
461- t .Fatalf ("os.MkdirAll() = %v" , err )
462- }
463-
464- state := & config.LibrarianState {
465- Image : "some/image:v1.2.3" ,
466- Libraries : []* config.LibraryState {
467- {
468- ID : "some-library" ,
469- APIs : []* config.API {
470- {
471- Path : "some/api" ,
472- ServiceConfig : "api_config.yaml" ,
473- Status : config .StatusExisting ,
474- },
475- },
476- SourceRoots : []string {"src/a" },
477- },
478- },
479- }
480- b , err := yaml .Marshal (state )
481- if err != nil {
482- t .Fatalf ("yaml.Marshal() = %v" , err )
483- }
484-
485- if err := os .WriteFile (stateFile , b , 0644 ); err != nil {
486- t .Fatalf ("os.WriteFile(%q, ...) = %v" , stateFile , err )
487- }
488- configFile := filepath .Join (test .cfg .Repo , config .LibrarianDir , pipelineConfigFile )
489- if err := os .WriteFile (configFile , []byte ("{}" ), 0644 ); err != nil {
490- t .Fatalf ("os.WriteFile(%q, ...) = %v" , configFile , err )
491- }
492- runGit (t , test .cfg .Repo , "add" , "." )
493- runGit (t , test .cfg .Repo , "commit" , "-m" , "add config" )
494- }
495-
496454 if test .cfg .APISource == "" && test .cfg .WorkRoot != "" {
497455 if test .name == "clone googleapis fails" {
498456 // The function will try to clone googleapis into the current work directory.
@@ -1647,50 +1605,3 @@ func TestCleanAndCopyLibrary(t *testing.T) {
16471605 })
16481606 }
16491607}
1650-
1651- // newTestGitRepo creates a new git repository in a temporary directory.
1652- func newTestGitRepo (t * testing.T ) gitrepo.Repository {
1653- t .Helper ()
1654- return newTestGitRepoWithState (t , true )
1655- }
1656-
1657- // newTestGitRepo creates a new git repository in a temporary directory.
1658- func newTestGitRepoWithState (t * testing.T , writeState bool ) gitrepo.Repository {
1659- t .Helper ()
1660- dir := t .TempDir ()
1661- remoteURL := "https://github.com/googleapis/librarian.git"
1662- runGit (t , dir , "init" )
1663- runGit (
t ,
dir ,
"config" ,
"user.email" ,
"[email protected] " )
1664- runGit (t , dir , "config" , "user.name" , "Test User" )
1665- if err := os .WriteFile (filepath .Join (dir , "README.md" ), []byte ("test" ), 0644 ); err != nil {
1666- t .Fatalf ("os.WriteFile: %v" , err )
1667- }
1668- if writeState {
1669- // Create an empty state.yaml file
1670- stateDir := filepath .Join (dir , config .LibrarianDir )
1671- if err := os .MkdirAll (stateDir , 0755 ); err != nil {
1672- t .Fatalf ("os.MkdirAll: %v" , err )
1673- }
1674- stateFile := filepath .Join (stateDir , "state.yaml" )
1675- if err := os .WriteFile (stateFile , []byte ("" ), 0644 ); err != nil {
1676- t .Fatalf ("os.WriteFile: %v" , err )
1677- }
1678- }
1679- runGit (t , dir , "add" , "." )
1680- runGit (t , dir , "commit" , "-m" , "initial commit" )
1681- runGit (t , dir , "remote" , "add" , "origin" , remoteURL )
1682- repo , err := gitrepo .NewRepository (& gitrepo.RepositoryOptions {Dir : dir })
1683- if err != nil {
1684- t .Fatalf ("gitrepo.Open(%q) = %v" , dir , err )
1685- }
1686- return repo
1687- }
1688-
1689- func runGit (t * testing.T , dir string , args ... string ) {
1690- t .Helper ()
1691- cmd := exec .Command ("git" , args ... )
1692- cmd .Dir = dir
1693- if err := cmd .Run (); err != nil {
1694- t .Fatalf ("git %v: %v" , args , err )
1695- }
1696- }
0 commit comments