@@ -95,7 +95,8 @@ func TestTidyCommand(t *testing.T) {
9595 configContent := `language: rust
9696sources:
9797 googleapis:
98- commit: abc123
98+ commit: 94ccedca05acb0bb60780789e93371c9e4100ddc
99+ sha256: fff40946e897d96bbdccd566cb993048a87029b7e08eacee3fe99eac792721ba
99100libraries:
100101 - name: google-cloud-storage-v1
101102 version: "1.0.0"
@@ -139,6 +140,10 @@ func TestTidy_DerivableFields(t *testing.T) {
139140 {
140141 name : "derivable fields removed" ,
141142 configContent : `
143+ sources:
144+ googleapis:
145+ commit: 94ccedca05acb0bb60780789e93371c9e4100ddc
146+ sha256: fff40946e897d96bbdccd566cb993048a87029b7e08eacee3fe99eac792721ba
142147libraries:
143148 - name: google-cloud-accessapproval-v1
144149 channels:
@@ -153,34 +158,28 @@ libraries:
153158 {
154159 name : "non-derivable path not removed" ,
155160 configContent : `
161+ sources:
162+ googleapis:
163+ commit: 94ccedca05acb0bb60780789e93371c9e4100ddc
164+ sha256: fff40946e897d96bbdccd566cb993048a87029b7e08eacee3fe99eac792721ba
156165libraries:
157- - name: google-cloud-api-servicecontrol-v1
158- channels:
159- - path: google/api/servicecontrol/v1
160- service_config: google/api/servicecontrol/v1/servicecontrol.yaml
161- ` ,
162- wantPath : "google/api/servicecontrol/v1" ,
163- wantSvcCfg : "google/api/servicecontrol/v1/servicecontrol.yaml" ,
164- wantNumLibs : 1 ,
165- wantNumChnls : 1 ,
166- },
167- {
168- name : "only derivable service config removed" ,
169- configContent : `
170- libraries:
171- - name: google-cloud-vision-v1
166+ - name: google-cloud-aiplatform-v1-schema-predict-instance
172167 channels:
173- - path: google/some/other/domain/vision/v1
174- service_config: google/some/other/domain/vision/ v1/vision_v1 .yaml
168+ - path: src/generated/cloud/aiplatform/schema/predict/instance
169+ service_config: google/cloud/aiplatform/ v1/schema/aiplatform_v1 .yaml
175170` ,
176- wantPath : "google/some/other/domain/vision/v1 " ,
177- wantSvcCfg : "" ,
171+ wantPath : "src/generated/cloud/aiplatform/schema/predict/instance " ,
172+ wantSvcCfg : "google/cloud/aiplatform/v1/schema/aiplatform_v1.yaml " ,
178173 wantNumLibs : 1 ,
179174 wantNumChnls : 1 ,
180175 },
181176 {
182177 name : "path needs to be resolved" ,
183178 configContent : `
179+ sources:
180+ googleapis:
181+ commit: 94ccedca05acb0bb60780789e93371c9e4100ddc
182+ sha256: fff40946e897d96bbdccd566cb993048a87029b7e08eacee3fe99eac792721ba
184183libraries:
185184 - name: google-cloud-vision-v1
186185 channels:
@@ -194,6 +193,10 @@ libraries:
194193 {
195194 name : "service config not derivable (no version at end of path)" ,
196195 configContent : `
196+ sources:
197+ googleapis:
198+ commit: 94ccedca05acb0bb60780789e93371c9e4100ddc
199+ sha256: fff40946e897d96bbdccd566cb993048a87029b7e08eacee3fe99eac792721ba
197200libraries:
198201 - name: google-cloud-speech
199202 channels:
@@ -208,6 +211,10 @@ libraries:
208211 {
209212 name : "channel removed if service config does not exist" ,
210213 configContent : `
214+ sources:
215+ googleapis:
216+ commit: 94ccedca05acb0bb60780789e93371c9e4100ddc
217+ sha256: fff40946e897d96bbdccd566cb993048a87029b7e08eacee3fe99eac792721ba
211218libraries:
212219 - name: google-cloud-orgpolicy-v1
213220 channels:
@@ -288,6 +295,10 @@ func TestTidy_DerivableOutput(t *testing.T) {
288295language: rust
289296default:
290297 output: generated/
298+ sources:
299+ googleapis:
300+ commit: 94ccedca05acb0bb60780789e93371c9e4100ddc
301+ sha256: fff40946e897d96bbdccd566cb993048a87029b7e08eacee3fe99eac792721ba
291302libraries:
292303 - name: google-cloud-secretmanager-v1
293304 output: generated/cloud/secretmanager/v1
@@ -297,7 +308,7 @@ libraries:
297308 if err := os .WriteFile (configPath , []byte (configContent ), 0644 ); err != nil {
298309 t .Fatal (err )
299310 }
300- if err := RunTidy (); err != nil {
311+ if err := RunTidy (t . Context () ); err != nil {
301312 t .Fatal (err )
302313 }
303314 cfg , err := yaml.Read [config.Config ](configPath )
@@ -323,6 +334,10 @@ func TestTidyLanguageConfig_Rust(t *testing.T) {
323334 name : "empty_module_removed" ,
324335 configContent : `
325336language: rust
337+ sources:
338+ googleapis:
339+ commit: 94ccedca05acb0bb60780789e93371c9e4100ddc
340+ sha256: fff40946e897d96bbdccd566cb993048a87029b7e08eacee3fe99eac792721ba
326341default:
327342 output: generated/
328343libraries:
@@ -367,3 +382,26 @@ libraries:
367382 })
368383 }
369384}
385+
386+ func TestTidyCommandMissingGoogleApisSource (t * testing.T ) {
387+ tempDir := t .TempDir ()
388+ t .Chdir (tempDir )
389+ configPath := filepath .Join (tempDir , librarianConfigPath )
390+ configContent := `language: rust
391+ libraries:
392+ - name: google-cloud-storage-v1
393+ version: "1.0.0"
394+ - name: google-cloud-bigquery-v1
395+ version: "2.0.0"
396+ `
397+ if err := os .WriteFile (configPath , []byte (configContent ), 0644 ); err != nil {
398+ t .Fatal (err )
399+ }
400+ err := Run (t .Context (), "librarian" , "tidy" )
401+ if err == nil {
402+ t .Fatalf ("expected error, got %v" , nil )
403+ }
404+ if ! errors .Is (err , errNoGoogleapiSourceInfo ) {
405+ t .Errorf ("mismatch error want %v got %v" , errNoGoogleapiSourceInfo , err )
406+ }
407+ }
0 commit comments