@@ -443,7 +443,10 @@ func TestRunPostProcessor(t *testing.T) {
443443 testhelper .RequireCommand (t , "compileProtos" )
444444
445445 repoRoot := t .TempDir ()
446- library := & config.Library {Name : "google-cloud-secretmanager" }
446+ library := & config.Library {
447+ Name : "google-cloud-secretmanager" ,
448+ APIs : []* config.API {{Path : "google/cloud/secretmanager/v1" }},
449+ }
447450 outDir := filepath .Join (repoRoot , "packages" , library .Name )
448451 if err := os .MkdirAll (outDir , 0755 ); err != nil {
449452 t .Fatal (err )
@@ -473,7 +476,10 @@ func TestRunPostProcessor_RemovesOwlBotYaml(t *testing.T) {
473476 testhelper .RequireCommand (t , "compileProtos" )
474477
475478 repoRoot := t .TempDir ()
476- library := & config.Library {Name : "google-cloud-test" }
479+ library := & config.Library {
480+ Name : "google-cloud-test" ,
481+ APIs : []* config.API {{Path : "google/cloud/test/v1" }},
482+ }
477483 outDir := filepath .Join (repoRoot , "packages" , library .Name )
478484 if err := os .MkdirAll (outDir , 0755 ); err != nil {
479485 t .Fatal (err )
@@ -513,7 +519,10 @@ func TestRunPostProcessor_RemovesCloudCommonResourcesProto(t *testing.T) {
513519 testhelper .RequireCommand (t , "compileProtos" )
514520
515521 repoRoot := t .TempDir ()
516- library := & config.Library {Name : "google-cloud-test" }
522+ library := & config.Library {
523+ Name : "google-cloud-test" ,
524+ APIs : []* config.API {{Path : "google/cloud/test/v1" }},
525+ }
517526 outDir := filepath .Join (repoRoot , "packages" , library .Name )
518527 if err := os .MkdirAll (outDir , 0755 ); err != nil {
519528 t .Fatal (err )
@@ -557,6 +566,7 @@ func TestRunPostProcessor_CustomScripts(t *testing.T) {
557566 repoRoot := t .TempDir ()
558567 library := & config.Library {
559568 Name : "google-cloud-secretmanager" ,
569+ APIs : []* config.API {{Path : "google/cloud/secretmanager/v1" }},
560570 Keep : []string {"librarian.js" , ".readme-partials.yaml" , "README.md" },
561571 }
562572 outDir := filepath .Join (repoRoot , "packages" , library .Name )
@@ -640,6 +650,7 @@ func TestRunPostProcessor_PreservesFiles(t *testing.T) {
640650 repoRoot := t .TempDir ()
641651 library := & config.Library {
642652 Name : "google-cloud-test" ,
653+ APIs : []* config.API {{Path : "google/cloud/test/v1" }},
643654 Keep : []string {"README.md" , ".readme-partials.yaml" , "system-test/.eslintrc.yml" },
644655 }
645656 outDir := filepath .Join (repoRoot , "packages" , library .Name )
@@ -1042,6 +1053,29 @@ func TestWriteRepoMetadata(t *testing.T) {
10421053 return w
10431054 },
10441055 },
1056+ {
1057+ name : "default version override" ,
1058+ library : & config.Library {
1059+ Name : "google-cloud-secretmanager" ,
1060+ APIs : []* config.API {
1061+ {Path : "google/cloud/secretmanager/v1" },
1062+ {Path : "google/cloud/secretmanager/v1beta" },
1063+ },
1064+ Nodejs : & config.NodejsPackage {
1065+ DefaultVersion : "v1beta" ,
1066+ },
1067+ },
1068+ want : func () * repometadata.RepoMetadata {
1069+ w := sample .RepoMetadata ()
1070+ w .DistributionName = "@google-cloud/secretmanager"
1071+ w .Language = cfg .Language
1072+ w .Repo = cfg .Repo
1073+ w .ClientDocumentation = "https://cloud.google.com/nodejs/docs/reference/secretmanager/latest"
1074+ w .ProductDocumentation = "https://cloud.google.com/secret-manager/docs"
1075+ w .DefaultVersion = "v1beta"
1076+ return w
1077+ },
1078+ },
10451079 } {
10461080 t .Run (test .name , func (t * testing.T ) {
10471081 outDir := t .TempDir ()
@@ -1076,6 +1110,7 @@ func TestRunPostProcessor_CustomScripts_RootRelativePath(t *testing.T) {
10761110 repoRoot := t .TempDir ()
10771111 library := & config.Library {
10781112 Name : "google-cloud-secretmanager" ,
1113+ APIs : []* config.API {{Path : "google/cloud/secretmanager/v1" }},
10791114 Keep : []string {"librarian.js" },
10801115 }
10811116
@@ -1450,3 +1485,47 @@ func TestRemoveRedundantLinterFiles(t *testing.T) {
14501485 })
14511486 }
14521487}
1488+
1489+ func TestResolveDefaultVersion (t * testing.T ) {
1490+ for _ , test := range []struct {
1491+ name string
1492+ lib * config.Library
1493+ want string
1494+ }{
1495+ {
1496+ name : "default to first API path" ,
1497+ lib : & config.Library {
1498+ APIs : []* config.API {
1499+ {Path : "google/cloud/test/v3" },
1500+ {Path : "google/cloud/test/v4" },
1501+ },
1502+ },
1503+ want : "v3" ,
1504+ },
1505+ {
1506+ name : "no APIs or override" ,
1507+ lib : & config.Library {},
1508+ want : "" ,
1509+ },
1510+ {
1511+ name : "override" ,
1512+ lib : & config.Library {
1513+ APIs : []* config.API {
1514+ {Path : "google/cloud/test/v3" },
1515+ {Path : "google/cloud/test/v4" },
1516+ },
1517+ Nodejs : & config.NodejsPackage {
1518+ DefaultVersion : "v4" ,
1519+ },
1520+ },
1521+ want : "v4" ,
1522+ },
1523+ } {
1524+ t .Run (test .name , func (t * testing.T ) {
1525+ got := resolveDefaultVersion (test .lib )
1526+ if diff := cmp .Diff (test .want , got ); diff != "" {
1527+ t .Errorf ("mismatch (-want +got):\n %s" , diff )
1528+ }
1529+ })
1530+ }
1531+ }
0 commit comments