@@ -197,9 +197,6 @@ func annotateMethodModel(t *testing.T) *api.API {
197197 {Name : "project" , ID : ".test.v1.Request.project" , Typez : api .STRING_TYPE },
198198 {Name : "zone" , ID : ".test.v1.Request.zone" , Typez : api .STRING_TYPE },
199199 {Name : "type" , ID : ".test.v1.Request.type" , Typez : api .STRING_TYPE },
200- {Name : "name" , ID : ".test.v1.Request.name" , Typez : api .STRING_TYPE },
201- {Name : "location" , ID : ".test.v1.Request.location" , Typez : api .STRING_TYPE },
202- {Name : "cluster" , ID : ".test.v1.Request.cluster" , Typez : api .STRING_TYPE },
203200 },
204201 }
205202 response := & api.Message {
@@ -314,61 +311,26 @@ func TestAnnotateMethodResourceNameTemplate(t *testing.T) {
314311 {"type" },
315312 })
316313
317- // Setup: Inject multiple bindings for the "Self" method
318- mSelf := model .State .MethodByID [".test.v1.ResourceService.Self" ]
319- mSelf .PathInfo .Bindings = []* api.PathBinding {
320- {
321- Verb : "GET" ,
322- PathTemplate : api .NewPathTemplate ().
323- WithLiteral ("v1" ).
324- WithVariableNamed ("name" ),
325- TargetResource : & api.TargetResource {
326- Template : api .ParseTemplateForTest ("//Test.googleapis.com/projects/{project}/locations/{location}/clusters/{cluster}" ),
327- FieldPaths : [][]string {{"name" }},
328- },
329- },
330- {
331- Verb : "GET" ,
332- PathTemplate : api .NewPathTemplate ().
333- WithLiteral ("v1" ).
334- WithLiteral ("projects" ).
335- WithVariableNamed ("project" ).
336- WithLiteral ("locations" ).
337- WithVariableNamed ("location" ).
338- WithLiteral ("clusters" ).
339- WithVariableNamed ("cluster" ),
340- TargetResource : & api.TargetResource {
341- Template : api .ParseTemplateForTest ("//Test.googleapis.com/projects/{project}/locations/{location}/clusters/{cluster}" ),
342- FieldPaths : [][]string {{"project" }, {"location" }, {"cluster" }},
343- },
344- },
345- {
346- Verb : "GET" ,
347- PathTemplate : api .NewPathTemplate (),
348- },
349- }
350-
351314 codec := newTestCodec (t , libconfig .SpecProtobuf , "" , map [string ]string {})
352315 _ , err = annotateModel (model , codec )
353316 if err != nil {
354317 t .Fatal (err )
355318 }
356319
357320 tests := []struct {
358- name string
359- id string
360- want * methodAnnotation
361- wantBindings []* pathBindingAnnotation
321+ name string
322+ id string
323+ want * methodAnnotation
362324 }{
363325 {
364326 name : "WithTargetResource" ,
365327 id : ".test.v1.ResourceService.move" ,
366328 want : & methodAnnotation {
367329 ResourceNameTemplate : "//Test.googleapis.com/projects/{}/zones/{}/types/{}" ,
368330 ResourceNameArgs : []string {
369- "var_project " ,
370- "var_zone " ,
371- "var_type " ,
331+ "Some(&req).map(|m| &m.project).map(|s| s.as_str()).unwrap_or( \" \" ) " ,
332+ "Some(&req).map(|m| &m.zone).map(|s| s.as_str()).unwrap_or( \" \" ) " ,
333+ "Some(&req).map(|m| &m.r#type).map(|s| s.as_str()).unwrap_or( \" \" ) " ,
372334 },
373335 HasResourceNameGeneration : true ,
374336 },
@@ -380,34 +342,6 @@ func TestAnnotateMethodResourceNameTemplate(t *testing.T) {
380342 HasResourceNameGeneration : false ,
381343 },
382344 },
383- {
384- name : "MultipleBindings" ,
385- id : ".test.v1.ResourceService.Self" ,
386- want : & methodAnnotation {
387- ResourceNameTemplate : "//Test.googleapis.com/projects/{}/locations/{}/clusters/{}" ,
388- ResourceNameArgs : []string {
389- "var_name" ,
390- },
391- HasResourceNameGeneration : true ,
392- },
393- wantBindings : []* pathBindingAnnotation {
394- {
395- HasResourceNameGeneration : true ,
396- ResourceNameTemplate : "//Test.googleapis.com/projects/{}/locations/{}/clusters/{}" ,
397- ResourceNameArgs : []string {"var_name" },
398- },
399- {
400- HasResourceNameGeneration : true ,
401- ResourceNameTemplate : "//Test.googleapis.com/projects/{}/locations/{}/clusters/{}" ,
402- ResourceNameArgs : []string {"var_project" , "var_location" , "var_cluster" },
403- },
404- {
405- HasResourceNameGeneration : true ,
406- ResourceNameTemplate : "" ,
407- ResourceNameArgs : nil ,
408- },
409- },
410- },
411345 }
412346
413347 for _ , tc := range tests {
@@ -425,15 +359,6 @@ func TestAnnotateMethodResourceNameTemplate(t *testing.T) {
425359 "HasResourceNameFields" , "InternalBuilders" )); diff != "" {
426360 t .Errorf ("mismatch (-want, +got):\n %s" , diff )
427361 }
428-
429- if tc .wantBindings != nil {
430- for i , wantBinding := range tc .wantBindings {
431- gotBinding := m .PathInfo .Bindings [i ].Codec .(* pathBindingAnnotation )
432- if diff := cmp .Diff (wantBinding , gotBinding , cmpopts .IgnoreFields (pathBindingAnnotation {}, "DetailedTracingAttributes" , "PathFmt" , "QueryParams" , "Substitutions" )); diff != "" {
433- t .Errorf ("binding %d mismatch (-want, +got):\n %s" , i , diff )
434- }
435- }
436- }
437362 })
438363 }
439364}
0 commit comments