From 5f1b00f00ea5b4a1db3ea8619b565857fd2b9d89 Mon Sep 17 00:00:00 2001 From: Thomas Rodgers Date: Wed, 10 Jul 2024 13:25:45 -0700 Subject: [PATCH] Remove resource_test_utils from go folder --- .../acctest/go/framework_test_utils.go | 48 +++++++++++++++++ .../acctest/go/resource_test_utils.go | 52 ------------------- ..._google_gke_hub_membership_binding_test.go | 2 +- .../resource_org_policy_policy_test.go | 4 +- ...ce_scc_project_notification_config_test.go | 2 +- ...rce_google_site_verification_token_test.go | 2 +- 6 files changed, 53 insertions(+), 57 deletions(-) delete mode 100644 mmv1/third_party/terraform/acctest/go/resource_test_utils.go diff --git a/mmv1/third_party/terraform/acctest/go/framework_test_utils.go b/mmv1/third_party/terraform/acctest/go/framework_test_utils.go index 4d4f113343ca..54cf5d88b2bf 100644 --- a/mmv1/third_party/terraform/acctest/go/framework_test_utils.go +++ b/mmv1/third_party/terraform/acctest/go/framework_test_utils.go @@ -2,10 +2,14 @@ package acctest import ( "context" + "fmt" "log" "testing" "github.com/hashicorp/terraform-plugin-framework/diag" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) func GetFwTestProvider(t *testing.T) *frameworkTestProvider { @@ -25,3 +29,47 @@ func GetFwTestProvider(t *testing.T) *frameworkTestProvider { return p } + +// General test utils + +// TestExtractResourceAttr navigates a test's state to find the specified resource (or data source) attribute and makes the value +// accessible via the attributeValue string pointer. +func TestExtractResourceAttr(resourceName string, attributeName string, attributeValue *string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] // To find a datasource, include `data.` at the start of the resourceName value + + if !ok { + return fmt.Errorf("resource name %s not found in state", resourceName) + } + + attrValue, ok := rs.Primary.Attributes[attributeName] + + if !ok { + return fmt.Errorf("attribute %s not found in resource %s state", attributeName, resourceName) + } + + *attributeValue = attrValue + + return nil + } +} + +// TestCheckAttributeValuesEqual compares two string pointers, which have been used to retrieve attribute values from the test's state. +func TestCheckAttributeValuesEqual(i *string, j *string) resource.TestCheckFunc { + return func(s *terraform.State) error { + if testStringValue(i) != testStringValue(j) { + return fmt.Errorf("attribute values are different, got %s and %s", testStringValue(i), testStringValue(j)) + } + + return nil + } +} + +// testStringValue returns string values from string pointers, handling nil pointers. +func testStringValue(sPtr *string) string { + if sPtr == nil { + return "" + } + + return *sPtr +} diff --git a/mmv1/third_party/terraform/acctest/go/resource_test_utils.go b/mmv1/third_party/terraform/acctest/go/resource_test_utils.go deleted file mode 100644 index 178fd5c54140..000000000000 --- a/mmv1/third_party/terraform/acctest/go/resource_test_utils.go +++ /dev/null @@ -1,52 +0,0 @@ -package acctest - -import ( - "fmt" - - "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/terraform" -) - -// General test utils - -// TestExtractResourceAttr navigates a test's state to find the specified resource (or data source) attribute and makes the value -// accessible via the attributeValue string pointer. -func TestExtractResourceAttr(resourceName string, attributeName string, attributeValue *string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[resourceName] // To find a datasource, include `data.` at the start of the resourceName value - - if !ok { - return fmt.Errorf("resource name %s not found in state", resourceName) - } - - attrValue, ok := rs.Primary.Attributes[attributeName] - - if !ok { - return fmt.Errorf("attribute %s not found in resource %s state", attributeName, resourceName) - } - - *attributeValue = attrValue - - return nil - } -} - -// TestCheckAttributeValuesEqual compares two string pointers, which have been used to retrieve attribute values from the test's state. -func TestCheckAttributeValuesEqual(i *string, j *string) resource.TestCheckFunc { - return func(s *terraform.State) error { - if testStringValue(i) != testStringValue(j) { - return fmt.Errorf("attribute values are different, got %s and %s", testStringValue(i), testStringValue(j)) - } - - return nil - } -} - -// testStringValue returns string values from string pointers, handling nil pointers. -func testStringValue(sPtr *string) string { - if sPtr == nil { - return "" - } - - return *sPtr -} diff --git a/mmv1/third_party/terraform/services/gkehub2/data_source_google_gke_hub_membership_binding_test.go b/mmv1/third_party/terraform/services/gkehub2/data_source_google_gke_hub_membership_binding_test.go index 094aad12c882..bab681b0d568 100644 --- a/mmv1/third_party/terraform/services/gkehub2/data_source_google_gke_hub_membership_binding_test.go +++ b/mmv1/third_party/terraform/services/gkehub2/data_source_google_gke_hub_membership_binding_test.go @@ -3,7 +3,7 @@ package gkehub2_test import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" ) diff --git a/mmv1/third_party/terraform/services/orgpolicy/resource_org_policy_policy_test.go b/mmv1/third_party/terraform/services/orgpolicy/resource_org_policy_policy_test.go index 078705bd22d9..adfa8d105ef5 100644 --- a/mmv1/third_party/terraform/services/orgpolicy/resource_org_policy_policy_test.go +++ b/mmv1/third_party/terraform/services/orgpolicy/resource_org_policy_policy_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "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" diff --git a/mmv1/third_party/terraform/services/securitycenter/resource_scc_project_notification_config_test.go b/mmv1/third_party/terraform/services/securitycenter/resource_scc_project_notification_config_test.go index c3416289682f..77e5328d7475 100644 --- a/mmv1/third_party/terraform/services/securitycenter/resource_scc_project_notification_config_test.go +++ b/mmv1/third_party/terraform/services/securitycenter/resource_scc_project_notification_config_test.go @@ -3,7 +3,7 @@ package securitycenter_test import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" ) diff --git a/mmv1/third_party/terraform/services/siteverification/data_source_google_site_verification_token_test.go b/mmv1/third_party/terraform/services/siteverification/data_source_google_site_verification_token_test.go index 96b5bdfb7721..17dd51040494 100644 --- a/mmv1/third_party/terraform/services/siteverification/data_source_google_site_verification_token_test.go +++ b/mmv1/third_party/terraform/services/siteverification/data_source_google_site_verification_token_test.go @@ -5,7 +5,7 @@ package siteverification_test import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-google/google/acctest" )