@@ -282,6 +282,199 @@ func TestIsSimpleMethod(t *testing.T) {
282282 }
283283}
284284
285+ func TestIsAIPStandard (t * testing.T ) {
286+ // Setup for a valid Get operation
287+ resourceType := "google.cloud.secretmanager.v1/Secret"
288+ resourceNameField := & Field {
289+ ResourceReference : & ResourceReference {
290+ Type : resourceType ,
291+ },
292+ }
293+ resource := & Resource {
294+ Type : resourceType ,
295+ Singular : "secret" ,
296+ }
297+ output := & Message {
298+ Resource : resource ,
299+ }
300+ validGetMethod := & Method {
301+ Name : "GetSecret" ,
302+ InputType : & Message {Name : "GetSecretRequest" , Fields : []* Field {resourceNameField }},
303+ OutputType : output ,
304+ }
305+
306+ // Setup for an invalid Get operation (e.g., wrong name)
307+ invalidGetMethod := & Method {
308+ Name : "ListSecrets" , // Not a Get method
309+ InputType : & Message {Name : "ListSecretsRequest" },
310+ OutputType : output ,
311+ }
312+
313+ testCases := []struct {
314+ name string
315+ method * Method
316+ want bool
317+ }{
318+ {
319+ name : "standard get method returns true" ,
320+ method : validGetMethod ,
321+ want : true ,
322+ },
323+ {
324+ name : "non-standard method returns false" ,
325+ method : invalidGetMethod ,
326+ want : false ,
327+ },
328+ }
329+
330+ for _ , tc := range testCases {
331+ t .Run (tc .name , func (t * testing.T ) {
332+ if got := tc .method .IsAIPStandard (); got != tc .want {
333+ t .Errorf ("IsAIPStandard() = %v, want %v" , got , tc .want )
334+ }
335+ })
336+ }
337+ }
338+
339+ func TestAIPStandardGetInfo (t * testing.T ) {
340+ resourceType := "google.cloud.secretmanager.v1/Secret"
341+ resourceNameField := & Field {
342+ ResourceReference : & ResourceReference {
343+ Type : resourceType ,
344+ },
345+ }
346+ resource := & Resource {
347+ Type : resourceType ,
348+ Singular : "secret" ,
349+ }
350+ output := & Message {
351+ Resource : resource ,
352+ }
353+ testCases := []struct {
354+ name string
355+ method * Method
356+ want * AIPStandardGetInfo
357+ }{
358+ {
359+ name : "valid get operation" ,
360+ method : & Method {
361+ Name : "GetSecret" ,
362+ InputType : & Message {Name : "GetSecretRequest" , Fields : []* Field {resourceNameField }},
363+ OutputType : output ,
364+ },
365+ want : & AIPStandardGetInfo {
366+ ResourceNameRequestField : resourceNameField ,
367+ },
368+ },
369+ {
370+ name : "method name is incorrect" ,
371+ method : & Method {
372+ Name : "Get" ,
373+ InputType : & Message {Name : "GetSecretRequest" , Fields : []* Field {resourceNameField }},
374+ OutputType : output ,
375+ },
376+ want : nil ,
377+ },
378+ {
379+ name : "request type name is incorrect" ,
380+ method : & Method {
381+ Name : "GetSecret" ,
382+ InputType : & Message {Name : "GetRequest" , Fields : []* Field {resourceNameField }},
383+ OutputType : output ,
384+ },
385+ want : nil ,
386+ },
387+ {
388+ name : "returns empty" ,
389+ method : & Method {
390+ Name : "GetSecret" ,
391+ InputType : & Message {Name : "GetSecretRequest" , Fields : []* Field {resourceNameField }},
392+ OutputType : output ,
393+ ReturnsEmpty : true ,
394+ },
395+ want : nil ,
396+ },
397+ {
398+ name : "output is not a resource" ,
399+ method : & Method {
400+ Name : "GetSecret" ,
401+ InputType : & Message {Name : "GetSecretRequest" , Fields : []* Field {resourceNameField }},
402+ OutputType : & Message {
403+ Resource : nil ,
404+ },
405+ },
406+ want : nil ,
407+ },
408+ {
409+ name : "request does not contain resource name field" ,
410+ method : & Method {
411+ Name : "GetSecret" ,
412+ InputType : & Message {Name : "GetSecretRequest" },
413+ OutputType : output ,
414+ },
415+ want : nil ,
416+ },
417+ {
418+ name : "pagination method is not a standard get operation" ,
419+ method : & Method {
420+ Name : "GetSecret" ,
421+ InputType : & Message {Name : "GetSecretRequest" , Fields : []* Field {resourceNameField }},
422+ OutputType : output ,
423+ Pagination : & Field {},
424+ },
425+ want : nil ,
426+ },
427+ {
428+ name : "client streaming method is not a standard get operation" ,
429+ method : & Method {
430+ Name : "GetSecret" ,
431+ InputType : & Message {Name : "GetSecretRequest" , Fields : []* Field {resourceNameField }},
432+ OutputType : output ,
433+ ClientSideStreaming : true ,
434+ },
435+ want : nil ,
436+ },
437+ {
438+ name : "server streaming method is not a standard get operation" ,
439+ method : & Method {
440+ Name : "GetSecret" ,
441+ InputType : & Message {Name : "GetSecretRequest" , Fields : []* Field {resourceNameField }},
442+ OutputType : output ,
443+ ServerSideStreaming : true ,
444+ },
445+ want : nil ,
446+ },
447+ {
448+ name : "LRO method is not a standard get operation" ,
449+ method : & Method {
450+ Name : "GetSecret" ,
451+ InputType : & Message {Name : "GetSecretRequest" , Fields : []* Field {resourceNameField }},
452+ OutputType : output ,
453+ OperationInfo : & OperationInfo {},
454+ },
455+ want : nil ,
456+ },
457+ {
458+ name : "Discovery LRO method is not a standard get operation" ,
459+ method : & Method {
460+ Name : "GetSecret" ,
461+ InputType : & Message {Name : "GetSecretRequest" , Fields : []* Field {resourceNameField }},
462+ OutputType : output ,
463+ DiscoveryLro : & DiscoveryLro {},
464+ },
465+ want : nil ,
466+ },
467+ }
468+ for _ , tc := range testCases {
469+ t .Run (tc .name , func (t * testing.T ) {
470+ got := tc .method .AIPStandardGetInfo ()
471+ if diff := cmp .Diff (tc .want , got ); diff != "" {
472+ t .Errorf ("AIPStandardGetInfo() mismatch (-want +got):\n %s" , diff )
473+ }
474+ })
475+ }
476+ }
477+
285478func TestFieldTypePredicates (t * testing.T ) {
286479 type TestCase struct {
287480 field * Field
0 commit comments