Skip to content

Commit

Permalink
feat(generator/dart): update the generated package names
Browse files Browse the repository at this point in the history
  • Loading branch information
devoncarew committed Feb 7, 2025
1 parent 85e1bc7 commit fb6efaf
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 6 deletions.
2 changes: 1 addition & 1 deletion generator/internal/dart/dart.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func modelPackageName(api *api.API, packageNameOverride string) string {
if len(packageNameOverride) > 0 {
return packageNameOverride
}
return api.Name
return "google_cloud_" + strcase.ToSnake(api.Name)
}

func validatePackageName(newPackage, elementName, sourceSpecificationPackageName string) error {
Expand Down
48 changes: 48 additions & 0 deletions generator/internal/dart/dart_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dart

import (
"io/fs"
"path/filepath"
"strings"
"testing"
)

func TestDart_GeneratedFiles(t *testing.T) {
files := generatedFiles()
if len(files) == 0 {
t.Errorf("expected a non-empty list of template files from generatedFiles()")
}
}

func TestDart_TemplatesAvailable(t *testing.T) {
var count = 0
fs.WalkDir(dartTemplates, "templates", func(path string, d fs.DirEntry, err error) error {
if filepath.Ext(path) != ".mustache" {
return nil
}
if strings.Count(d.Name(), ".") == 1 {
// skip partials
return nil
}
count++
return nil
})

if count == 0 {
t.Errorf("no go templates found")
}
}
4 changes: 1 addition & 3 deletions generator/internal/dart/darttemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type modelAnnotations struct {
CopyrightYear string
BoilerPlate []string
DefaultHost string
DartPackage string
DocLines []string
}

Expand Down Expand Up @@ -155,8 +154,7 @@ func annotateModel(model *api.API, options map[string]string) (*modelAnnotations
}
return ""
}(),
DartPackage: "google_" + modelPackageName(model, packageNameOverride),
DocLines: strings.Split(model.Description, "\n"),
DocLines: strings.Split(model.Description, "\n"),
}

model.Codec = ann
Expand Down
36 changes: 36 additions & 0 deletions generator/internal/dart/darttemplate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dart

import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/googleapis/google-cloud-rust/generator/internal/api"
)

func TestDart_AnnotateModel(t *testing.T) {
model := api.NewTestAPI([]*api.Message{}, []*api.Enum{}, []*api.Service{})
_, err := annotateModel(model, map[string]string{})
if err != nil {
t.Fatal(err)
}

codec := model.Codec.(*modelAnnotations)

if diff := cmp.Diff("google_cloud_test", codec.PackageName); diff != "" {
t.Errorf("mismatch in Codec.PackageName (-want, +got)\n:%s", diff)
}
}
2 changes: 1 addition & 1 deletion generator/internal/dart/templates/pubspec.yaml.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.
#{{{.}}}
{{/Codec.BoilerPlate}}

name: {{Codec.DartPackage}}
name: {{Codec.PackageName}}
description: The Google Cloud client library for the {{Title}}.
version: 0.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#
# Code generated by sidekick. DO NOT EDIT.

name: google_secretmanager
name: google_cloud_secretmanager
description: The Google Cloud client library for the Secret Manager API.
version: 0.1.0

Expand Down

0 comments on commit fb6efaf

Please sign in to comment.