Skip to content

Commit c535df0

Browse files
auto generate tests from samples (#4991) (#3456)
Co-authored-by: Cameron Thornton <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Cameron Thornton <[email protected]>
1 parent ea2fed8 commit c535df0

11 files changed

+604
-515
lines changed

.changelog/4991.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
```release-note:none
2+
```

google-beta/provider_dcl_client_creation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
cloudbuild "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuild/beta"
2222
dataproc "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/dataproc/beta"
2323
eventarc "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/eventarc/beta"
24-
gke_hub "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta"
24+
gkehub "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta"
2525
)
2626

2727
func NewDCLAssuredWorkloadsClient(config *Config, userAgent, billingProject string) *assuredworkloads.Client {
@@ -128,7 +128,7 @@ func NewDCLEventarcClient(config *Config, userAgent, billingProject string) *eve
128128
return eventarc.NewClient(dclConfig)
129129
}
130130

131-
func NewDCLGkeHubClient(config *Config, userAgent, billingProject string) *gke_hub.Client {
131+
func NewDCLGkeHubClient(config *Config, userAgent, billingProject string) *gkehub.Client {
132132
dclClientOptions := dcl.WithHTTPClient(config.client)
133133
dclUserAgentOptions := dcl.WithUserAgent(userAgent)
134134
dclLoggerOptions := dcl.WithLogger(dclLogger{})
@@ -151,5 +151,5 @@ func NewDCLGkeHubClient(config *Config, userAgent, billingProject string) *gke_h
151151
)
152152
}
153153

154-
return gke_hub.NewClient(dclConfig)
154+
return gkehub.NewClient(dclConfig)
155155
}

google-beta/resource_assured_workloads_workload_test.go renamed to google-beta/resource_assured_workloads_workload_generated_test.go

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
115
package google
216

317
import (
418
"context"
519
"fmt"
6-
"log"
7-
"strconv"
8-
"strings"
9-
"testing"
10-
"time"
11-
1220
dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
1321
assuredworkloads "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/assuredworkloads/beta"
1422
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1523
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1624
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
25+
"log"
26+
"strconv"
27+
"strings"
28+
"testing"
29+
"time"
1730
)
1831

19-
func TestAccAssuredWorkloadsWorkload_basic(t *testing.T) {
32+
func TestAccAssuredWorkloadsWorkload_BasicHandWritten(t *testing.T) {
2033
t.Parallel()
2134

2235
context := map[string]interface{}{
23-
"random_suffix": randString(t, 10),
24-
"org_id": getTestOrgFromEnv(t),
25-
"billing_account": getTestBillingAccountFromEnv(t),
36+
"billing_acct": getTestBillingAccountFromEnv(t),
37+
"org_id": getTestOrgFromEnv(t),
38+
"region": getTestRegionFromEnv(),
39+
"random_suffix": randString(t, 10),
2640
}
2741

2842
vcrTest(t, resource.TestCase{
@@ -31,35 +45,36 @@ func TestAccAssuredWorkloadsWorkload_basic(t *testing.T) {
3145
CheckDestroy: testAccCheckAssuredWorkloadsWorkloadDestroyProducer(t),
3246
Steps: []resource.TestStep{
3347
{
34-
Config: testAccAssuredWorkloadsWorkload_basic(context),
48+
Config: testAccAssuredWorkloadsWorkload_BasicHandWritten(context),
49+
Check: resource.ComposeTestCheckFunc(deleteAssuredWorkloadProvisionedResources(t)),
3550
},
3651
{
37-
ResourceName: "google_assured_workloads_workload.meep",
52+
ResourceName: "google_assured_workloads_workload.primary",
3853
ImportState: true,
3954
ImportStateVerify: true,
4055
ImportStateVerifyIgnore: []string{"billing_account", "kms_settings", "resource_settings", "provisioned_resources_parent"},
4156
},
4257
{
43-
Config: testAccAssuredWorkloadsWorkload_basicUpdate(context),
44-
Check: deleteAssuredWorkloadProvisionedResources(t),
58+
Config: testAccAssuredWorkloadsWorkload_BasicHandWrittenUpdate0(context),
59+
Check: resource.ComposeTestCheckFunc(deleteAssuredWorkloadProvisionedResources(t)),
4560
},
4661
{
47-
ResourceName: "google_assured_workloads_workload.meep",
62+
ResourceName: "google_assured_workloads_workload.primary",
4863
ImportState: true,
4964
ImportStateVerify: true,
5065
ImportStateVerifyIgnore: []string{"billing_account", "kms_settings", "resource_settings", "provisioned_resources_parent"},
5166
},
5267
},
5368
})
5469
}
55-
56-
func TestAccAssuredWorkloadsWorkload_full(t *testing.T) {
70+
func TestAccAssuredWorkloadsWorkload_FullHandWritten(t *testing.T) {
5771
t.Parallel()
5872

5973
context := map[string]interface{}{
60-
"random_suffix": randString(t, 10),
61-
"org_id": getTestOrgFromEnv(t),
62-
"billing_account": getTestBillingAccountFromEnv(t),
74+
"billing_acct": getTestBillingAccountFromEnv(t),
75+
"org_id": getTestOrgFromEnv(t),
76+
"region": getTestRegionFromEnv(),
77+
"random_suffix": randString(t, 10),
6378
}
6479

6580
vcrTest(t, resource.TestCase{
@@ -68,11 +83,11 @@ func TestAccAssuredWorkloadsWorkload_full(t *testing.T) {
6883
CheckDestroy: testAccCheckAssuredWorkloadsWorkloadDestroyProducer(t),
6984
Steps: []resource.TestStep{
7085
{
71-
Config: testAccAssuredWorkloadsWorkload_full(context),
86+
Config: testAccAssuredWorkloadsWorkload_FullHandWritten(context),
7287
Check: resource.ComposeTestCheckFunc(deleteAssuredWorkloadProvisionedResources(t)),
7388
},
7489
{
75-
ResourceName: "google_assured_workloads_workload.meep",
90+
ResourceName: "google_assured_workloads_workload.primary",
7691
ImportState: true,
7792
ImportStateVerify: true,
7893
ImportStateVerifyIgnore: []string{"billing_account", "kms_settings", "resource_settings", "provisioned_resources_parent"},
@@ -160,53 +175,53 @@ func deleteAssuredWorkloadProvisionedResources(t *testing.T) resource.TestCheckF
160175
}
161176
}
162177

163-
func testAccAssuredWorkloadsWorkload_basic(context map[string]interface{}) string {
178+
func testAccAssuredWorkloadsWorkload_BasicHandWritten(context map[string]interface{}) string {
164179
return Nprintf(`
165-
resource "google_assured_workloads_workload" "meep" {
166-
display_name = "workloadExample-%{random_suffix}"
180+
resource "google_assured_workloads_workload" "primary" {
181+
display_name = "workload%{random_suffix}"
167182
labels = {
168-
a = "a"
183+
a = "b"
169184
}
170-
billing_account = "billingAccounts/%{billing_account}"
185+
billing_account = "billingAccounts/%{billing_acct}"
171186
compliance_regime = "FEDRAMP_MODERATE"
172187
provisioned_resources_parent = google_folder.folder1.name
173188
organization = "%{org_id}"
174189
location = "us-central1"
175190
}
176191
177192
resource "google_folder" "folder1" {
178-
display_name = "tf-test-%{random_suffix}"
193+
display_name = "workload%{random_suffix}"
179194
parent = "organizations/%{org_id}"
180195
}
181196
`, context)
182197
}
183198

184-
func testAccAssuredWorkloadsWorkload_basicUpdate(context map[string]interface{}) string {
199+
func testAccAssuredWorkloadsWorkload_BasicHandWrittenUpdate0(context map[string]interface{}) string {
185200
return Nprintf(`
186-
resource "google_assured_workloads_workload" "meep" {
187-
display_name = "updatedExample-%{random_suffix}"
201+
resource "google_assured_workloads_workload" "primary" {
202+
display_name = "workload%{random_suffix}"
188203
labels = {
189204
a = "b"
190205
}
191-
billing_account = "billingAccounts/%{billing_account}"
206+
billing_account = "billingAccounts/%{billing_acct}"
192207
compliance_regime = "FEDRAMP_MODERATE"
193208
provisioned_resources_parent = google_folder.folder1.name
194209
organization = "%{org_id}"
195210
location = "us-central1"
196211
}
197212
198213
resource "google_folder" "folder1" {
199-
display_name = "tf-test-%{random_suffix}"
214+
display_name = "workload%{random_suffix}"
200215
parent = "organizations/%{org_id}"
201216
}
202217
`, context)
203218
}
204219

205-
func testAccAssuredWorkloadsWorkload_full(context map[string]interface{}) string {
220+
func testAccAssuredWorkloadsWorkload_FullHandWritten(context map[string]interface{}) string {
206221
return Nprintf(`
207-
resource "google_assured_workloads_workload" "meep" {
208-
display_name = "workloadExample-%{random_suffix}"
209-
billing_account = "billingAccounts/%{billing_account}"
222+
resource "google_assured_workloads_workload" "primary" {
223+
display_name = "workload%{random_suffix}"
224+
billing_account = "billingAccounts/%{billing_acct}"
210225
compliance_regime = "FEDRAMP_MODERATE"
211226
organization = "%{org_id}"
212227
location = "us-central1"
@@ -218,7 +233,7 @@ resource "google_assured_workloads_workload" "meep" {
218233
}
219234
220235
resource "google_folder" "folder1" {
221-
display_name = "tf-test-%{random_suffix}"
236+
display_name = "workload%{random_suffix}"
222237
parent = "organizations/%{org_id}"
223238
}
224239
`, context)
@@ -227,7 +242,7 @@ resource "google_folder" "folder1" {
227242
func testAccCheckAssuredWorkloadsWorkloadDestroyProducer(t *testing.T) func(s *terraform.State) error {
228243
return func(s *terraform.State) error {
229244
for name, rs := range s.RootModule().Resources {
230-
if rs.Type != "google_assured_workloads_workload" {
245+
if rs.Type != "rs.google_assured_workloads_workload" {
231246
continue
232247
}
233248
if strings.HasPrefix(name, "data.") {
@@ -237,28 +252,27 @@ func testAccCheckAssuredWorkloadsWorkloadDestroyProducer(t *testing.T) func(s *t
237252
config := googleProviderConfig(t)
238253

239254
billingProject := ""
240-
241255
if config.BillingProject != "" {
242256
billingProject = config.BillingProject
243257
}
244258

245-
billingAccount := rs.Primary.Attributes["billing_account"]
246-
location := rs.Primary.Attributes["location"]
247-
name := rs.Primary.Attributes["name"]
248-
249259
obj := &assuredworkloads.Workload{
250-
BillingAccount: dcl.String(rs.Primary.Attributes["billing_account"]),
251-
Location: dcl.String(rs.Primary.Attributes["location"]),
252-
Name: dcl.StringOrNil(rs.Primary.Attributes["name"]),
260+
BillingAccount: dcl.String(rs.Primary.Attributes["billing_account"]),
261+
ComplianceRegime: assuredworkloads.WorkloadComplianceRegimeEnumRef(rs.Primary.Attributes["compliance_regime"]),
262+
DisplayName: dcl.String(rs.Primary.Attributes["display_name"]),
263+
Location: dcl.String(rs.Primary.Attributes["location"]),
264+
Organization: dcl.String(rs.Primary.Attributes["organization"]),
265+
ProvisionedResourcesParent: dcl.String(rs.Primary.Attributes["provisioned_resources_parent"]),
266+
CreateTime: dcl.StringOrNil(rs.Primary.Attributes["create_time"]),
267+
Name: dcl.StringOrNil(rs.Primary.Attributes["name"]),
253268
}
254269

255270
client := NewDCLAssuredWorkloadsClient(config, config.userAgent, billingProject)
256271
_, err := client.GetWorkload(context.Background(), obj)
257272
if err == nil {
258-
return fmt.Errorf("AssuredWorkloadsWorkloadResource still exists at %s, %s, %s", billingAccount, location, name)
273+
return fmt.Errorf("google_assured_workloads_workload still exists %v", obj)
259274
}
260275
}
261-
262276
return nil
263277
}
264278
}

0 commit comments

Comments
 (0)