Skip to content

Commit cbc3d5f

Browse files
authored
tgc-revival: Modify the handwritten test file name (#15959)
1 parent 4827ca2 commit cbc3d5f

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

mmv1/products/cloudtasks/Queue.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ properties:
186186
If zero, then the task age is unlimited.
187187
default_from_api: true
188188
diff_suppress_func: 'suppressOmittedMaxDuration'
189+
custom_tgc_flatten: 'templates/tgc_next/custom_flatten/cloudtasks_queue_max_retry_duration.go.tmpl'
189190
- name: 'minBackoff'
190191
type: String
191192
description: |

mmv1/products/vpcaccess/Connector.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ examples:
6565
network_name: 'default'
6666
test_vars_overrides:
6767
'network_name': 'acctest.BootstrapSharedServiceNetworkingConnection(t, "vpc-access-connector")'
68+
tgc_tests:
69+
- name: TestAccVPCAccessConnector_vpcAccessConnectorThroughput_usingThroughputOrInstancesLimits
70+
skip: 'For instances vs throughput, prefer instances during cai2hcl conversion as throughput is discouraged.'
6871
parameters:
6972
- name: 'region'
7073
type: String

mmv1/provider/terraform_tgc_next.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
//
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
2+
if v == nil || v == "" {
3+
return "0s"
4+
}
5+
return v
6+
}

0 commit comments

Comments
 (0)