@@ -55,11 +55,11 @@ func TestRunGenerate(t *testing.T) {
5555 t .Run (test .name , func (t * testing.T ) {
5656 workRoot := t .TempDir ()
5757 repo := t .TempDir ()
58- APISourceRepo := t .TempDir ()
58+ apiSourceRepo := t .TempDir ()
5959 if err := initRepo (t , repo , initialRepoStateDir ); err != nil {
6060 t .Fatalf ("languageRepo prepare test error = %v" , err )
6161 }
62- if err := initRepo (t , APISourceRepo , localAPISource ); err != nil {
62+ if err := initRepo (t , apiSourceRepo , localAPISource ); err != nil {
6363 t .Fatalf ("APISouceRepo prepare test error = %v" , err )
6464 }
6565
@@ -71,7 +71,7 @@ func TestRunGenerate(t *testing.T) {
7171 fmt .Sprintf ("--api=%s" , test .api ),
7272 fmt .Sprintf ("--output=%s" , workRoot ),
7373 fmt .Sprintf ("--repo=%s" , repo ),
74- fmt .Sprintf ("--api-source=%s" , APISourceRepo ),
74+ fmt .Sprintf ("--api-source=%s" , apiSourceRepo ),
7575 )
7676 cmd .Stderr = os .Stderr
7777 cmd .Stdout = os .Stdout
@@ -165,11 +165,11 @@ func TestCleanAndCopy(t *testing.T) {
165165
166166 workRoot := t .TempDir ()
167167 repo := t .TempDir ()
168- APISourceRepo := t .TempDir ()
168+ apiSourceRepo := t .TempDir ()
169169 if err := initRepo (t , repo , repoInitDir ); err != nil {
170170 t .Fatalf ("languageRepo prepare test error = %v" , err )
171171 }
172- if err := initRepo (t , APISourceRepo , localAPISource ); err != nil {
172+ if err := initRepo (t , apiSourceRepo , localAPISource ); err != nil {
173173 t .Fatalf ("APISouceRepo prepare test error = %v" , err )
174174 }
175175
@@ -181,7 +181,7 @@ func TestCleanAndCopy(t *testing.T) {
181181 fmt .Sprintf ("--api=%s" , apiToGenerate ),
182182 fmt .Sprintf ("--output=%s" , workRoot ),
183183 fmt .Sprintf ("--repo=%s" , repo ),
184- fmt .Sprintf ("--api-source=%s" , APISourceRepo ),
184+ fmt .Sprintf ("--api-source=%s" , apiSourceRepo ),
185185 )
186186 cmd .Stderr = os .Stderr
187187 cmd .Stdout = os .Stdout
@@ -244,11 +244,11 @@ func TestRunConfigure(t *testing.T) {
244244 t .Run (test .name , func (t * testing.T ) {
245245 workRoot := t .TempDir ()
246246 repo := t .TempDir ()
247- APISourceRepo := t .TempDir ()
247+ apiSourceRepo := t .TempDir ()
248248 if err := initRepo (t , repo , initialRepoStateDir ); err != nil {
249249 t .Fatalf ("prepare test error = %v" , err )
250250 }
251- if err := initRepo (t , APISourceRepo , test .apiSource ); err != nil {
251+ if err := initRepo (t , apiSourceRepo , test .apiSource ); err != nil {
252252 t .Fatalf ("APISouceRepo prepare test error = %v" , err )
253253 }
254254
@@ -260,7 +260,7 @@ func TestRunConfigure(t *testing.T) {
260260 fmt .Sprintf ("--api=%s" , test .api ),
261261 fmt .Sprintf ("--output=%s" , workRoot ),
262262 fmt .Sprintf ("--repo=%s" , repo ),
263- fmt .Sprintf ("--api-source=%s" , APISourceRepo ),
263+ fmt .Sprintf ("--api-source=%s" , apiSourceRepo ),
264264 fmt .Sprintf ("--library=%s" , test .library ),
265265 )
266266 cmd .Stderr = os .Stderr
@@ -313,6 +313,87 @@ func TestRunConfigure(t *testing.T) {
313313 }
314314}
315315
316+ func TestRunGenerate_MultipleLibraries (t * testing.T ) {
317+ const localAPISource = "testdata/e2e/generate/api_root"
318+
319+ for _ , test := range []struct {
320+ name string
321+ initialRepoStateDir string
322+ expectError bool
323+ expectedFiles []string
324+ unexpectedFiles []string
325+ }{
326+ {
327+ name : "Multiple libraries generated successfully" ,
328+ initialRepoStateDir : "testdata/e2e/generate/multi_repo_init" ,
329+ expectedFiles : []string {"pubsub/example.txt" , "future/example.txt" },
330+ unexpectedFiles : []string {},
331+ },
332+ {
333+ name : "One library fails to generate" ,
334+ initialRepoStateDir : "testdata/e2e/generate/multi_repo_one_fails_init" ,
335+ expectedFiles : []string {"pubsub/example.txt" },
336+ unexpectedFiles : []string {"future/example.txt" },
337+ },
338+ {
339+ name : "All libraries fail to generate" ,
340+ initialRepoStateDir : "testdata/e2e/generate/multi_repo_all_fail_init" ,
341+ expectError : true ,
342+ expectedFiles : []string {},
343+ unexpectedFiles : []string {"future/example.txt" , "another-future/example.txt" },
344+ },
345+ } {
346+ t .Run (test .name , func (t * testing.T ) {
347+ workRoot := t .TempDir ()
348+ repo := t .TempDir ()
349+ apiSourceRepo := t .TempDir ()
350+
351+ if err := initRepo (t , repo , test .initialRepoStateDir ); err != nil {
352+ t .Fatalf ("languageRepo prepare test error = %v" , err )
353+ }
354+ if err := initRepo (t , apiSourceRepo , localAPISource ); err != nil {
355+ t .Fatalf ("APISouceRepo prepare test error = %v" , err )
356+ }
357+
358+ cmd := exec .Command (
359+ "go" ,
360+ "run" ,
361+ "github.com/googleapis/librarian/cmd/librarian" ,
362+ "generate" ,
363+ fmt .Sprintf ("--output=%s" , workRoot ),
364+ fmt .Sprintf ("--repo=%s" , repo ),
365+ fmt .Sprintf ("--api-source=%s" , apiSourceRepo ),
366+ )
367+ cmd .Stderr = os .Stderr
368+ cmd .Stdout = os .Stdout
369+ err := cmd .Run ()
370+
371+ if test .expectError {
372+ if err == nil {
373+ t .Fatal ("librarian generate command should fail" )
374+ }
375+ return
376+ }
377+
378+ if err != nil {
379+ t .Fatalf ("librarian generate command error = %v" , err )
380+ }
381+
382+ for _ , f := range test .expectedFiles {
383+ if _ , err := os .Stat (filepath .Join (repo , f )); os .IsNotExist (err ) {
384+ t .Errorf ("%s should have been copied" , f )
385+ }
386+ }
387+
388+ for _ , f := range test .unexpectedFiles {
389+ if _ , err := os .Stat (filepath .Join (repo , f )); ! os .IsNotExist (err ) {
390+ t .Errorf ("%s should not have been copied" , f )
391+ }
392+ }
393+ })
394+ }
395+ }
396+
316397// initRepo initiates a git repo in the given directory, copy
317398// files from source directory and create a commit.
318399func initRepo (t * testing.T , dir , source string ) error {
0 commit comments