Skip to content

Commit 723c009

Browse files
authored
fix(internal/librarian/dart): fill name-override to sidekick config (#3783)
Fill the `name-override` from library config to sidekick config. For #3580
1 parent 7b15b9e commit 723c009

2 files changed

Lines changed: 135 additions & 0 deletions

File tree

internal/librarian/dart/generate.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func toSidekickConfig(library *config.Library, ch *config.API, googleapisDir str
5656
"googleapis-root": googleapisDir,
5757
}
5858

59+
if library.Dart != nil && library.Dart.NameOverride != "" {
60+
source["name-override"] = library.Dart.NameOverride
61+
}
62+
5963
api, err := serviceconfig.Find(googleapisDir, ch.Path)
6064
if err != nil {
6165
return nil, err

internal/librarian/dart/generate_test.go

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
package dart
1616

1717
import (
18+
"errors"
1819
"os"
1920
"path/filepath"
2021
"strings"
2122
"testing"
2223

2324
"github.com/google/go-cmp/cmp"
2425
"github.com/googleapis/librarian/internal/config"
26+
sidekickconfig "github.com/googleapis/librarian/internal/sidekick/config"
2527
"github.com/googleapis/librarian/internal/testhelper"
2628
)
2729

@@ -361,3 +363,132 @@ func TestBuildCodec(t *testing.T) {
361363
})
362364
}
363365
}
366+
367+
func TestToSidekickConfig(t *testing.T) {
368+
googleapisDir := t.TempDir()
369+
for _, test := range []struct {
370+
name string
371+
library *config.Library
372+
channel *config.API
373+
googleapisDir string
374+
want *sidekickconfig.Config
375+
wantErr error
376+
}{
377+
{
378+
name: "empty library",
379+
library: &config.Library{},
380+
channel: &config.API{
381+
Path: "google/example/v1",
382+
},
383+
googleapisDir: googleapisDir,
384+
want: &sidekickconfig.Config{
385+
General: sidekickconfig.GeneralConfig{
386+
Language: "dart",
387+
SpecificationFormat: "protobuf",
388+
ServiceConfig: "",
389+
SpecificationSource: "google/example/v1",
390+
},
391+
Source: map[string]string{
392+
"googleapis-root": googleapisDir,
393+
},
394+
Codec: map[string]string{},
395+
},
396+
},
397+
{
398+
name: "with name-override",
399+
library: &config.Library{
400+
Dart: &config.DartPackage{
401+
NameOverride: "override-name",
402+
},
403+
},
404+
channel: &config.API{
405+
Path: "google/example/v1",
406+
},
407+
googleapisDir: googleapisDir,
408+
want: &sidekickconfig.Config{
409+
General: sidekickconfig.GeneralConfig{
410+
Language: "dart",
411+
SpecificationFormat: "protobuf",
412+
ServiceConfig: "",
413+
SpecificationSource: "google/example/v1",
414+
},
415+
Source: map[string]string{
416+
"googleapis-root": googleapisDir,
417+
"name-override": "override-name",
418+
},
419+
Codec: map[string]string{},
420+
},
421+
},
422+
{
423+
name: "with dart package",
424+
library: &config.Library{
425+
Dart: &config.DartPackage{
426+
APIKeysEnvironmentVariables: "GOOGLE_API_KEY",
427+
Dependencies: "dep-1,dep-2",
428+
DevDependencies: "dev-dep-1,dev-dep-2",
429+
ExtraImports: "extra-imports",
430+
IssueTrackerURL: "https://tracker/issues",
431+
LibraryPathOverride: "library-path-override",
432+
NotForPublication: "false",
433+
PartFile: "part-file",
434+
ReadmeAfterTitleText: "readme-after-title-text",
435+
ReadmeQuickstartText: "readme-quickstart-text",
436+
RepositoryURL: "https://github.com/googleapis/google-cloud-dart",
437+
Packages: map[string]string{
438+
"package:googleapis_auth": "^2.0.0",
439+
},
440+
Prefixes: map[string]string{
441+
"prefix:google.logging.type": "logging_type",
442+
},
443+
Protos: map[string]string{
444+
"proto:google.api": "package:google_cloud_api/api.dart",
445+
},
446+
},
447+
},
448+
channel: &config.API{
449+
Path: "google/example/v1",
450+
},
451+
googleapisDir: googleapisDir,
452+
want: &sidekickconfig.Config{
453+
General: sidekickconfig.GeneralConfig{
454+
Language: "dart",
455+
SpecificationFormat: "protobuf",
456+
ServiceConfig: "",
457+
SpecificationSource: "google/example/v1",
458+
},
459+
Source: map[string]string{
460+
"googleapis-root": googleapisDir,
461+
},
462+
Codec: map[string]string{
463+
"api-keys-environment-variables": "GOOGLE_API_KEY",
464+
"dependencies": "dep-1,dep-2",
465+
"dev-dependencies": "dev-dep-1,dev-dep-2",
466+
"extra-imports": "extra-imports",
467+
"issue-tracker-url": "https://tracker/issues",
468+
"library-path-override": "library-path-override",
469+
"not-for-publication": "false",
470+
"package:googleapis_auth": "^2.0.0",
471+
"part-file": "part-file",
472+
"prefix:prefix:google.logging.type": "logging_type",
473+
"proto:proto:google.api": "package:google_cloud_api/api.dart",
474+
"readme-after-title-text": "readme-after-title-text",
475+
"readme-quickstart-text": "readme-quickstart-text",
476+
"repository-url": "https://github.com/googleapis/google-cloud-dart",
477+
},
478+
},
479+
},
480+
} {
481+
t.Run(test.name, func(t *testing.T) {
482+
got, err := toSidekickConfig(test.library, test.channel, test.googleapisDir)
483+
if test.wantErr != nil {
484+
if !errors.Is(err, test.wantErr) {
485+
t.Errorf("toSidekickConfig() error = %v, wantErr %v", err, test.wantErr)
486+
}
487+
return
488+
}
489+
if diff := cmp.Diff(test.want, got); diff != "" {
490+
t.Errorf("mismatch (-want +got):\n%s", diff)
491+
}
492+
})
493+
}
494+
}

0 commit comments

Comments
 (0)