Skip to content

Commit 86a4ada

Browse files
authored
fix(internal/librarian): rename toSidekickConfig and update test cases (#3791)
Renames `ToSidekickConfig` to `libraryToSidekickConfig` in comparison to `moduleToSidekickConfig` and update base test cases to use secretmanager instead of storage. `google-cloud-storage` in rust is a veneer library in [config](https://github.com/googleapis/google-cloud-rust/blob/eb74294ad2a9302a5d3aff82fd585a41bc489abc/librarian.yaml#L1323) and would never go through `libraryToSidekickConfig` logic (`moduleToSidekickConfig` processes veneer ones). For #3627
1 parent 025de5a commit 86a4ada

3 files changed

Lines changed: 65 additions & 48 deletions

File tree

internal/librarian/rust/codec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
sidekickconfig "github.com/googleapis/librarian/internal/sidekick/config"
2424
)
2525

26-
func toSidekickConfig(library *config.Library, ch *config.API, sources *Sources) (*sidekickconfig.Config, error) {
26+
func libraryToSidekickConfig(library *config.Library, ch *config.API, sources *Sources) (*sidekickconfig.Config, error) {
2727
specFormat := "protobuf"
2828
if library.SpecificationFormat != "" {
2929
specFormat = library.SpecificationFormat

internal/librarian/rust/codec_test.go

Lines changed: 63 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func absPath(t *testing.T, p string) string {
4040
return abs
4141
}
4242

43-
func TestToSidekickConfig(t *testing.T) {
43+
func TestLibraryToSidekickConfig(t *testing.T) {
4444
for _, test := range []struct {
4545
name string
4646
library *config.Library
@@ -50,89 +50,96 @@ func TestToSidekickConfig(t *testing.T) {
5050
{
5151
name: "minimal config",
5252
library: &config.Library{
53-
Name: "google-cloud-storage",
54-
Rust: &config.RustCrate{},
53+
Name: "google-cloud-secretmanager",
54+
Rust: &config.RustCrate{},
55+
Veneer: true,
5556
},
5657
api: &config.API{
57-
Path: "google/cloud/storage/v1",
58+
Path: "google/cloud/secretmanager/v1",
5859
},
5960
want: &sidekickconfig.Config{
6061
General: sidekickconfig.GeneralConfig{
6162
Language: "rust",
6263
SpecificationFormat: "protobuf",
63-
SpecificationSource: "google/cloud/storage/v1",
64+
SpecificationSource: "google/cloud/secretmanager/v1",
65+
ServiceConfig: "google/cloud/secretmanager/v1/secretmanager_v1.yaml",
6466
},
6567
Source: map[string]string{
6668
"googleapis-root": absPath(t, googleapisRoot),
6769
"roots": "googleapis",
70+
"title-override": "Secret Manager API",
6871
},
6972
Codec: map[string]string{
70-
"package-name-override": "google-cloud-storage",
73+
"package-name-override": "google-cloud-secretmanager",
7174
},
7275
},
7376
},
7477
{
7578
name: "with version and release level",
7679
library: &config.Library{
77-
Name: "google-cloud-storage",
80+
Name: "google-cloud-secretmanager",
7881
Version: "0.1.0",
7982
ReleaseLevel: "preview",
8083
Rust: &config.RustCrate{
8184
Roots: []string{"googleapis"},
8285
},
8386
},
8487
api: &config.API{
85-
Path: "google/cloud/storage/v1",
88+
Path: "google/cloud/secretmanager/v1",
8689
},
8790
want: &sidekickconfig.Config{
8891
General: sidekickconfig.GeneralConfig{
8992
Language: "rust",
9093
SpecificationFormat: "protobuf",
91-
SpecificationSource: "google/cloud/storage/v1",
94+
SpecificationSource: "google/cloud/secretmanager/v1",
95+
ServiceConfig: "google/cloud/secretmanager/v1/secretmanager_v1.yaml",
9296
},
9397
Source: map[string]string{
9498
"googleapis-root": absPath(t, googleapisRoot),
9599
"roots": "googleapis",
100+
"title-override": "Secret Manager API",
96101
},
97102
Codec: map[string]string{
98103
"version": "0.1.0",
99104
"release-level": "preview",
100-
"package-name-override": "google-cloud-storage",
105+
"package-name-override": "google-cloud-secretmanager",
101106
},
102107
},
103108
},
104109
{
105110
name: "with copyright year",
106111
library: &config.Library{
107-
Name: "google-cloud-storage",
112+
Name: "google-cloud-secretmanager",
108113
CopyrightYear: "2024",
109114
Rust: &config.RustCrate{
110115
Roots: []string{"googleapis"},
111116
},
112117
},
113118
api: &config.API{
114-
Path: "google/cloud/storage/v1",
119+
Path: "google/cloud/secretmanager/v1",
115120
},
116121
want: &sidekickconfig.Config{
117122
General: sidekickconfig.GeneralConfig{
118123
Language: "rust",
119124
SpecificationFormat: "protobuf",
120-
SpecificationSource: "google/cloud/storage/v1",
125+
SpecificationSource: "google/cloud/secretmanager/v1",
126+
ServiceConfig: "google/cloud/secretmanager/v1/secretmanager_v1.yaml",
121127
},
122128
Source: map[string]string{
123129
"googleapis-root": absPath(t, googleapisRoot),
124130
"roots": "googleapis",
131+
"title-override": "Secret Manager API",
125132
},
126133
Codec: map[string]string{
127134
"copyright-year": "2024",
128-
"package-name-override": "google-cloud-storage",
135+
"package-name-override": "google-cloud-secretmanager",
129136
},
130137
},
131138
},
132139
{
133140
name: "with rust config",
134141
library: &config.Library{
135-
Name: "google-cloud-storage",
142+
Name: "google-cloud-secretmanager",
136143
Keep: []string{"src/extra-module.rs"},
137144
Rust: &config.RustCrate{
138145
RustDefault: config.RustDefault{
@@ -152,17 +159,19 @@ func TestToSidekickConfig(t *testing.T) {
152159
},
153160
},
154161
api: &config.API{
155-
Path: "google/cloud/storage/v1",
162+
Path: "google/cloud/secretmanager/v1",
156163
},
157164
want: &sidekickconfig.Config{
158165
General: sidekickconfig.GeneralConfig{
159166
Language: "rust",
160167
SpecificationFormat: "protobuf",
161-
SpecificationSource: "google/cloud/storage/v1",
168+
SpecificationSource: "google/cloud/secretmanager/v1",
169+
ServiceConfig: "google/cloud/secretmanager/v1/secretmanager_v1.yaml",
162170
},
163171
Source: map[string]string{
164172
"googleapis-root": absPath(t, googleapisRoot),
165173
"roots": "googleapis",
174+
"title-override": "Secret Manager API",
166175
},
167176
Codec: map[string]string{
168177
"module-path": "gcs",
@@ -178,42 +187,44 @@ func TestToSidekickConfig(t *testing.T) {
178187
"default-features": "default-feature",
179188
"extra-modules": "extra-module",
180189
"template-override": "custom-template",
181-
"package-name-override": "google-cloud-storage",
190+
"package-name-override": "google-cloud-secretmanager",
182191
},
183192
},
184193
},
185194
{
186195
name: "with skip publish (not for publication)",
187196
library: &config.Library{
188-
Name: "google-cloud-storage",
197+
Name: "google-cloud-secretmanager",
189198
SkipPublish: true,
190199
Rust: &config.RustCrate{
191200
Roots: []string{"googleapis"},
192201
},
193202
},
194203
api: &config.API{
195-
Path: "google/cloud/storage/v1",
204+
Path: "google/cloud/secretmanager/v1",
196205
},
197206
want: &sidekickconfig.Config{
198207
General: sidekickconfig.GeneralConfig{
199208
Language: "rust",
200209
SpecificationFormat: "protobuf",
201-
SpecificationSource: "google/cloud/storage/v1",
210+
SpecificationSource: "google/cloud/secretmanager/v1",
211+
ServiceConfig: "google/cloud/secretmanager/v1/secretmanager_v1.yaml",
202212
},
203213
Source: map[string]string{
204214
"googleapis-root": absPath(t, googleapisRoot),
205215
"roots": "googleapis",
216+
"title-override": "Secret Manager API",
206217
},
207218
Codec: map[string]string{
208219
"not-for-publication": "true",
209-
"package-name-override": "google-cloud-storage",
220+
"package-name-override": "google-cloud-secretmanager",
210221
},
211222
},
212223
},
213224
{
214225
name: "with package dependencies",
215226
library: &config.Library{
216-
Name: "google-cloud-storage",
227+
Name: "google-cloud-secretmanager",
217228
Rust: &config.RustCrate{
218229
RustDefault: config.RustDefault{
219230
PackageDependencies: []*config.RustPackageDependency{
@@ -230,96 +241,102 @@ func TestToSidekickConfig(t *testing.T) {
230241
},
231242
},
232243
api: &config.API{
233-
Path: "google/cloud/storage/v1",
244+
Path: "google/cloud/secretmanager/v1",
234245
},
235246
want: &sidekickconfig.Config{
236247
General: sidekickconfig.GeneralConfig{
237248
Language: "rust",
238249
SpecificationFormat: "protobuf",
239-
SpecificationSource: "google/cloud/storage/v1",
250+
SpecificationSource: "google/cloud/secretmanager/v1",
251+
ServiceConfig: "google/cloud/secretmanager/v1/secretmanager_v1.yaml",
240252
},
241253
Source: map[string]string{
242254
"googleapis-root": absPath(t, googleapisRoot),
243255
"roots": "googleapis",
256+
"title-override": "Secret Manager API",
244257
},
245258
Codec: map[string]string{
246259
"package:tokio": "package=tokio,source=1.0,force-used=true,used-if=feature = \"async\",feature=async",
247-
"package-name-override": "google-cloud-storage",
260+
"package-name-override": "google-cloud-secretmanager",
248261
},
249262
},
250263
},
251264
{
252265
name: "with documentation overrides",
253266
library: &config.Library{
254-
Name: "google-cloud-storage",
267+
Name: "google-cloud-secretmanager",
255268
Rust: &config.RustCrate{
256269
DocumentationOverrides: []config.RustDocumentationOverride{
257270
{
258-
ID: ".google.cloud.storage.v1.Bucket.name",
259-
Match: "bucket name",
260-
Replace: "the name of the bucket",
271+
ID: ".google.cloud.secretmanager.v1.Secret.name",
272+
Match: "secret name",
273+
Replace: "the name of the Secret",
261274
},
262275
},
263276
},
264277
},
265278
api: &config.API{
266-
Path: "google/cloud/storage/v1",
279+
Path: "google/cloud/secretmanager/v1",
267280
},
268281
want: &sidekickconfig.Config{
269282
General: sidekickconfig.GeneralConfig{
270283
Language: "rust",
271284
SpecificationFormat: "protobuf",
272-
SpecificationSource: "google/cloud/storage/v1",
285+
SpecificationSource: "google/cloud/secretmanager/v1",
286+
ServiceConfig: "google/cloud/secretmanager/v1/secretmanager_v1.yaml",
273287
},
274288
Source: map[string]string{
275289
"googleapis-root": absPath(t, googleapisRoot),
276290
"roots": "googleapis",
291+
"title-override": "Secret Manager API",
277292
},
278293
Codec: map[string]string{
279-
"package-name-override": "google-cloud-storage",
294+
"package-name-override": "google-cloud-secretmanager",
280295
},
281296
CommentOverrides: []sidekickconfig.DocumentationOverride{
282297
{
283-
ID: ".google.cloud.storage.v1.Bucket.name",
284-
Match: "bucket name",
285-
Replace: "the name of the bucket",
298+
ID: ".google.cloud.secretmanager.v1.Secret.name",
299+
Match: "secret name",
300+
Replace: "the name of the Secret",
286301
},
287302
},
288303
},
289304
},
290305
{
291-
name: "with pagination overrides",
306+
name: "with pagination secretmanager",
292307
library: &config.Library{
293-
Name: "google-cloud-storage",
308+
Name: "google-cloud-secretmanager",
294309
Rust: &config.RustCrate{
295310
PaginationOverrides: []config.RustPaginationOverride{
296311
{
297-
ID: ".google.cloud.storage.v1.Storage.ListBuckets",
298-
ItemField: "buckets",
312+
ID: ".google.cloud.secretmanager.v1.Secret.ListSecrets",
313+
ItemField: "secrets",
299314
},
300315
},
301316
},
302317
},
303318
api: &config.API{
304-
Path: "google/cloud/storage/v1",
319+
Path: "google/cloud/secretmanager/v1",
305320
},
306321
want: &sidekickconfig.Config{
307322
General: sidekickconfig.GeneralConfig{
308323
Language: "rust",
309324
SpecificationFormat: "protobuf",
310-
SpecificationSource: "google/cloud/storage/v1",
325+
SpecificationSource: "google/cloud/secretmanager/v1",
326+
ServiceConfig: "google/cloud/secretmanager/v1/secretmanager_v1.yaml",
311327
},
312328
Source: map[string]string{
313329
"googleapis-root": absPath(t, googleapisRoot),
314330
"roots": "googleapis",
331+
"title-override": "Secret Manager API",
315332
},
316333
Codec: map[string]string{
317-
"package-name-override": "google-cloud-storage",
334+
"package-name-override": "google-cloud-secretmanager",
318335
},
319336
PaginationOverrides: []sidekickconfig.PaginationOverride{
320337
{
321-
ID: ".google.cloud.storage.v1.Storage.ListBuckets",
322-
ItemField: "buckets",
338+
ID: ".google.cloud.secretmanager.v1.Secret.ListSecrets",
339+
ItemField: "secrets",
323340
},
324341
},
325342
},
@@ -652,7 +669,7 @@ func TestToSidekickConfig(t *testing.T) {
652669
Showcase: absPath(t, showcaseRoot),
653670
}
654671

655-
got, err := toSidekickConfig(test.library, test.api, sources)
672+
got, err := libraryToSidekickConfig(test.library, test.api, sources)
656673
if err != nil {
657674
t.Fatal(err)
658675
}

internal/librarian/rust/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func Generate(ctx context.Context, library *config.Library, sources *Sources) er
4848
return fmt.Errorf("the Rust generator only supports a single api per library")
4949
}
5050

51-
sidekickConfig, err := toSidekickConfig(library, library.APIs[0], sources)
51+
sidekickConfig, err := libraryToSidekickConfig(library, library.APIs[0], sources)
5252
if err != nil {
5353
return err
5454
}

0 commit comments

Comments
 (0)