@@ -353,9 +353,8 @@ func (tgc TerraformGoogleConversionNext) addTestsFromHandwrittenTests(object *ap
353353 if object .ProductMetadata == nil {
354354 return nil
355355 }
356- product := object .ProductMetadata
357- productName := google .Underscore (product .Name )
358- resourceFullName := fmt .Sprintf ("%s_%s" , productName , google .Underscore (object .Name ))
356+ productName := strings .ToLower (tgc .Product .Name )
357+ resourceFullName := tgc .ResourceGoFilename (* object )
359358 handwrittenTestFilePath := fmt .Sprintf ("third_party/terraform/services/%s/resource_%s_test.go" , productName , resourceFullName )
360359 data , err := os .ReadFile (handwrittenTestFilePath )
361360 for err != nil {
@@ -397,6 +396,42 @@ func (tgc TerraformGoogleConversionNext) addTestsFromHandwrittenTests(object *ap
397396 return nil
398397}
399398
399+ // Similar to FullResourceName, but override-aware to prevent things like ending in _test.
400+ // Non-Go files should just use FullResourceName.
401+ func (tgc * TerraformGoogleConversionNext ) ResourceGoFilename (object api.Resource ) string {
402+ // early exit if no override is set
403+ if object .FilenameOverride == "" {
404+ return tgc .FullResourceName (object )
405+ }
406+
407+ resName := object .FilenameOverride
408+
409+ var productName string
410+ if tgc .Product .LegacyName != "" {
411+ productName = tgc .Product .LegacyName
412+ } else {
413+ productName = google .Underscore (tgc .Product .Name )
414+ }
415+
416+ return fmt .Sprintf ("%s_%s" , productName , resName )
417+ }
418+
419+ func (tgc * TerraformGoogleConversionNext ) FullResourceName (object api.Resource ) string {
420+ // early exit- resource-level legacy names override the product too
421+ if object .LegacyName != "" {
422+ return strings .Replace (object .LegacyName , "google_" , "" , 1 )
423+ }
424+
425+ var productName string
426+ if tgc .Product .LegacyName != "" {
427+ productName = tgc .Product .LegacyName
428+ } else {
429+ productName = google .Underscore (tgc .Product .Name )
430+ }
431+
432+ return fmt .Sprintf ("%s_%s" , productName , google .Underscore (object .Name ))
433+ }
434+
400435// Generates the list of resources, and gets the count of resources.
401436// The resource object has the format
402437//
0 commit comments