Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YpNo committed Dec 13, 2024
1 parent 7fe5f78 commit 253459b
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package gkehub2_test

import (
"fmt"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
)

func TestAccDataSourceGoogleGkeHubFeature_basic(t *testing.T) {
Expand Down Expand Up @@ -34,7 +39,7 @@ func testAccDataSourceGoogleGkeHubFeature_basic(context map[string]interface{})
resource "google_gke_hub_feature" "example" {
location = "us-central1"
project = "%{project}"
name = "configmanagement"
name = "servicemesh"
}
data "google_gke_hub_feature" "example" {
Expand All @@ -44,3 +49,42 @@ data "google_gke_hub_feature" "example" {
}
`, context)
}

func testAccCheckGoogleGkeHubFeatureDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_gke_hub_feature" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

config := acctest.GoogleProviderConfig(t)

url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{GKEHub2BasePath}}projects/{{project}}/locations/{{location}}/features/{{name}}")
if err != nil {
return err
}

billingProject := ""

if config.BillingProject != "" {
billingProject = config.BillingProject
}

_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "GET",
Project: billingProject,
RawURL: url,
UserAgent: config.UserAgent,
})
if err == nil {
return fmt.Errorf("GKEHub2Feature still exists at %s", url)
}
}

return nil
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package gkehub2_test

import (
"fmt"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
)

func TestAccDataSourceGoogleGKEHub2MembershipBinding_basic(t *testing.T) {
Expand Down Expand Up @@ -68,3 +73,42 @@ data "google_gke_hub_membership_binding" "example" {
}
`, context)
}

func testAccCheckGKEHub2MembershipBindingDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_gke_hub_membership_binding" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

config := acctest.GoogleProviderConfig(t)

url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{GKEHub2BasePath}}projects/{{project}}/locations/{{location}}/memberships/{{membership_id}}/bindings/{{membership_binding_id}}")
if err != nil {
return err
}

billingProject := ""

if config.BillingProject != "" {
billingProject = config.BillingProject
}

_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "GET",
Project: billingProject,
RawURL: url,
UserAgent: config.UserAgent,
})
if err == nil {
return fmt.Errorf("GKEHub2MembershipBinding still exists at %s", url)
}
}

return nil
}
}

0 comments on commit 253459b

Please sign in to comment.