Skip to content

Commit 662ef2d

Browse files
authored
tgc-revival: fix the compute subnetwork tests (#15751)
1 parent c20da38 commit 662ef2d

File tree

4 files changed

+65
-31
lines changed

4 files changed

+65
-31
lines changed

mmv1/products/compute/Subnetwork.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ examples:
111111
vars:
112112
subnetwork_name: 'internal-ipv6-test-subnetwork'
113113
network_name: 'internal-ipv6-test-network'
114-
tgc_skip_test: 'internalIpv6Prefix is changed to C + O, but TGC uses latest provider version to run tests and does not have this change.'
115114
- name: 'subnetwork_purpose_private_nat'
116115
primary_resource_id: 'subnetwork-purpose-private-nat'
117116
min_version: 'beta'
@@ -150,7 +149,6 @@ examples:
150149
vars:
151150
subnetwork_name: 'subnet-ipv6-only'
152151
network_name: 'network-ipv6-only'
153-
tgc_skip_test: 'internalIpv6Prefix is changed to C + O, but TGC uses latest provider version to run tests and does not have this change.'
154152
- name: 'subnetwork_with_subnet_mode_pdp'
155153
primary_resource_id: 'subnetwork-with-subnet-mode-pdp'
156154
exclude_docs: true
@@ -169,7 +167,6 @@ examples:
169167
ip_collection_url: '"projects/tf-static-byoip/regions/us-central1/publicDelegatedPrefixes/internal-ipv6-subnet-mode-test-sub-pdp"'
170168
test_vars_overrides:
171169
ip_collection_url: '"projects/tf-static-byoip/regions/us-central1/publicDelegatedPrefixes/internal-ipv6-subnet-mode-test-sub-pdp"'
172-
tgc_skip_test: 'internalIpv6Prefix is changed to C + O, but TGC uses latest provider version to run tests and does not have this change.'
173170
- name: 'subnetwork_with_internal_subnet_mode_pdp_explicit_ip_prefix'
174171
primary_resource_id: 'subnetwork-with-internal-subnet-mode-pdp-explicit-ip-prefix'
175172
exclude_docs: true
@@ -181,7 +178,6 @@ examples:
181178
test_vars_overrides:
182179
internal_ipv6_prefix: 'fmt.Sprintf("2001:db8:1:%d::/64", acctest.RandIntRange(t, 0, 9999))'
183180
ip_collection_url: '"projects/tf-static-byoip/regions/us-central1/publicDelegatedPrefixes/internal-ipv6-subnet-mode-test-sub-pdp-explicit-prefix"'
184-
tgc_skip_test: 'internalIpv6Prefix is changed to C + O, but TGC uses latest provider version to run tests and does not have this change.'
185181
- name: 'subnetwork_ipv6_only_external'
186182
primary_resource_id: 'subnetwork-ipv6-only'
187183
exclude_docs: true

mmv1/templates/tgc_next/test/test_file.go.tmpl

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,34 @@ import (
2020
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/test"
2121
)
2222

23-
{{ range $t := $.TGCTests }}
24-
func {{ $t.Name }}(t *testing.T) {
25-
{{- if $t.Skip }}
26-
t.Skip("{{$t.Skip}}")
27-
{{- end }}
28-
t.Parallel()
29-
30-
test.BidirectionalConversion(
31-
t,
32-
[]string{
33-
{{- range $field := $.TGCTestIgnorePropertiesToStrings }}
34-
"{{ $field }}",
35-
{{- end }}
23+
func TestAcc{{$.ResourceName}}(t *testing.T) {
24+
tests := []test.TestCase{
25+
{{- range $t := $.TGCTests }}
26+
{
27+
Name: "{{ $t.Name }}",
28+
Skip: "{{ $t.Skip }}",
3629
},
37-
)
38-
}
3930
{{- end }}
31+
}
32+
33+
for _, tt := range tests {
34+
tt := tt
35+
36+
t.Run(tt.Name, func(t *testing.T) {
37+
t.Parallel()
38+
39+
if tt.Skip != "" {
40+
t.Skipf("Skipping %s test case: This case is currently disabled due to Issue.", tt.Name)
41+
}
42+
43+
test.BidirectionalConversion(
44+
t,
45+
[]string{
46+
{{- range $field := $.TGCTestIgnorePropertiesToStrings }}
47+
"{{ $field }}",
48+
{{- end }}
49+
},
50+
)
51+
})
52+
}
53+
}

mmv1/third_party/tgc_next/test/assert_test_files.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ var (
3636

3737
func BidirectionalConversion(t *testing.T, ignoredFields []string) {
3838
testName := t.Name()
39-
stepNumbers, err := getStepNumbers(testName)
39+
subTestName := GetSubTestName(testName)
40+
if subTestName == "" {
41+
t.Skipf("The subtest is unavailable")
42+
}
43+
44+
stepNumbers, err := getStepNumbers(subTestName)
4045
if err != nil {
4146
t.Fatalf("error preparing the input data: %v", err)
4247
}
@@ -45,21 +50,21 @@ func BidirectionalConversion(t *testing.T, ignoredFields []string) {
4550
t.Skipf("test steps are unavailable")
4651
}
4752

53+
// Create a temporary directory for running terraform.
54+
tfDir, err := os.MkdirTemp(tmpDir, "terraform")
55+
if err != nil {
56+
t.Fatalf("error creating a temporary directory for running terraform: %v", err)
57+
}
58+
defer os.RemoveAll(tfDir)
59+
4860
logger := zaptest.NewLogger(t)
4961

5062
for _, stepN := range stepNumbers {
51-
// Create a temporary directory for running terraform.
52-
tfDir, err := os.MkdirTemp(tmpDir, fmt.Sprintf("terraform%d", stepN))
53-
if err != nil {
54-
t.Fatalf("error creating a temporary directory for running terraform: %v", err)
55-
}
56-
defer os.RemoveAll(tfDir)
57-
58-
subtestName := fmt.Sprintf("step%d", stepN)
59-
t.Run(subtestName, func(t *testing.T) {
63+
stepName := fmt.Sprintf("step%d", stepN)
64+
t.Run(stepName, func(t *testing.T) {
6065
retries := 0
6166
flakyAction := func(ctx context.Context) error {
62-
testData, err := prepareTestData(testName, stepN, retries)
67+
testData, err := prepareTestData(subTestName, stepN, retries)
6368
retries++
6469
log.Printf("Starting the attempt %d", retries)
6570
if err != nil {
@@ -74,7 +79,7 @@ func BidirectionalConversion(t *testing.T, ignoredFields []string) {
7479
// Otherwise, test all of the resources in the test.
7580
primaryResource := testData.PrimaryResource
7681
resourceTestData := testData.ResourceTestData
77-
tName := fmt.Sprintf("%s_%s", testName, subtestName)
82+
tName := fmt.Sprintf("%s_%s", subTestName, stepName)
7883
if primaryResource != "" {
7984
t.Logf("Test for the primary resource %s begins.", primaryResource)
8085
err = testSingleResource(t, tName, resourceTestData[primaryResource], tfDir, ignoredFields, logger, true)

mmv1/third_party/tgc_next/test/utils.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,22 @@ func DeepCopyMap(source interface{}, destination interface{}) error {
123123

124124
return nil
125125
}
126+
127+
type TestCase struct {
128+
Name string
129+
Skip string
130+
}
131+
132+
func GetSubTestName(fullTestName string) string {
133+
parts := strings.Split(fullTestName, "/")
134+
135+
// Get the index of the last element
136+
lastIndex := len(parts) - 1
137+
138+
// Check for an empty or malformed string
139+
if lastIndex < 0 {
140+
return ""
141+
}
142+
143+
return parts[lastIndex]
144+
}

0 commit comments

Comments
 (0)