Skip to content

Commit 253459b

Browse files
committed
Fixing tests
1 parent 7fe5f78 commit 253459b

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

mmv1/third_party/terraform/services/gkehub2/data_source_google_gke_hub_feature_test.go

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package gkehub2_test
22

33
import (
4+
"fmt"
5+
"strings"
46
"testing"
57

68
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-testing/terraform"
710
"github.com/hashicorp/terraform-provider-google/google/acctest"
11+
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
12+
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
813
)
914

1015
func TestAccDataSourceGoogleGkeHubFeature_basic(t *testing.T) {
@@ -34,7 +39,7 @@ func testAccDataSourceGoogleGkeHubFeature_basic(context map[string]interface{})
3439
resource "google_gke_hub_feature" "example" {
3540
location = "us-central1"
3641
project = "%{project}"
37-
name = "configmanagement"
42+
name = "servicemesh"
3843
}
3944
4045
data "google_gke_hub_feature" "example" {
@@ -44,3 +49,42 @@ data "google_gke_hub_feature" "example" {
4449
}
4550
`, context)
4651
}
52+
53+
func testAccCheckGoogleGkeHubFeatureDestroyProducer(t *testing.T) func(s *terraform.State) error {
54+
return func(s *terraform.State) error {
55+
for name, rs := range s.RootModule().Resources {
56+
if rs.Type != "google_gke_hub_feature" {
57+
continue
58+
}
59+
if strings.HasPrefix(name, "data.") {
60+
continue
61+
}
62+
63+
config := acctest.GoogleProviderConfig(t)
64+
65+
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{GKEHub2BasePath}}projects/{{project}}/locations/{{location}}/features/{{name}}")
66+
if err != nil {
67+
return err
68+
}
69+
70+
billingProject := ""
71+
72+
if config.BillingProject != "" {
73+
billingProject = config.BillingProject
74+
}
75+
76+
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
77+
Config: config,
78+
Method: "GET",
79+
Project: billingProject,
80+
RawURL: url,
81+
UserAgent: config.UserAgent,
82+
})
83+
if err == nil {
84+
return fmt.Errorf("GKEHub2Feature still exists at %s", url)
85+
}
86+
}
87+
88+
return nil
89+
}
90+
}

mmv1/third_party/terraform/services/gkehub2/data_source_google_gke_hub_membership_binding_test.go

+44
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package gkehub2_test
22

33
import (
4+
"fmt"
5+
"strings"
46
"testing"
57

68
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-testing/terraform"
710
"github.com/hashicorp/terraform-provider-google/google/acctest"
811
"github.com/hashicorp/terraform-provider-google/google/envvar"
12+
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
13+
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
914
)
1015

1116
func TestAccDataSourceGoogleGKEHub2MembershipBinding_basic(t *testing.T) {
@@ -68,3 +73,42 @@ data "google_gke_hub_membership_binding" "example" {
6873
}
6974
`, context)
7075
}
76+
77+
func testAccCheckGKEHub2MembershipBindingDestroyProducer(t *testing.T) func(s *terraform.State) error {
78+
return func(s *terraform.State) error {
79+
for name, rs := range s.RootModule().Resources {
80+
if rs.Type != "google_gke_hub_membership_binding" {
81+
continue
82+
}
83+
if strings.HasPrefix(name, "data.") {
84+
continue
85+
}
86+
87+
config := acctest.GoogleProviderConfig(t)
88+
89+
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{GKEHub2BasePath}}projects/{{project}}/locations/{{location}}/memberships/{{membership_id}}/bindings/{{membership_binding_id}}")
90+
if err != nil {
91+
return err
92+
}
93+
94+
billingProject := ""
95+
96+
if config.BillingProject != "" {
97+
billingProject = config.BillingProject
98+
}
99+
100+
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
101+
Config: config,
102+
Method: "GET",
103+
Project: billingProject,
104+
RawURL: url,
105+
UserAgent: config.UserAgent,
106+
})
107+
if err == nil {
108+
return fmt.Errorf("GKEHub2MembershipBinding still exists at %s", url)
109+
}
110+
}
111+
112+
return nil
113+
}
114+
}

0 commit comments

Comments
 (0)