forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add acceptance tests for provider configuration behaviour using `add_…
…terraform_attribution_label` and `terraform_attribution_label_addition_strategy` (GoogleCloudPlatform#11884)
- Loading branch information
1 parent
e6af55b
commit 1347042
Showing
6 changed files
with
398 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...ird_party/terraform/fwprovider/framework_provider_add_terraform_attribution_label_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package fwprovider_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
) | ||
|
||
// TestAccFwProvider_add_terraform_attribution_label is a series of acc tests asserting how the plugin-framework provider handles add_terraform_attribution_label arguments | ||
// It is plugin-framework specific because the HCL used provisions plugin-framework-implemented resources | ||
// It is a counterpart to TestAccSdkProvider_add_terraform_attribution_label | ||
func TestAccFwProvider_add_terraform_attribution_label(t *testing.T) { | ||
testCases := map[string]func(t *testing.T){ | ||
// Configuring the provider using inputs | ||
"when add_terraform_attribution_label is set in the config, the value is set in the provider meta data": testAccFwProvider_add_terraform_attribution_label_configUsed, | ||
"when add_terraform_attribution_label is unset in the config, the default value 'true' is NOT set on the provider meta data": testAccFwProvider_add_terraform_attribution_label_defaultValue, | ||
} | ||
|
||
for name, tc := range testCases { | ||
// shadow the tc variable into scope so that when | ||
// the loop continues, if t.Run hasn't executed tc(t) | ||
// yet, we don't have a race condition | ||
// see https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables | ||
tc := tc | ||
t.Run(name, func(t *testing.T) { | ||
tc(t) | ||
}) | ||
} | ||
} | ||
|
||
func testAccFwProvider_add_terraform_attribution_label_configUsed(t *testing.T) { | ||
acctest.SkipIfVcr(t) // Test doesn't interact with API | ||
|
||
contextFalse := map[string]interface{}{ | ||
"add_terraform_attribution_label": "false", | ||
} | ||
contextTrue := map[string]interface{}{ | ||
"add_terraform_attribution_label": "true", | ||
} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
// No PreCheck for checking ENVs | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccFwProvider_add_terraform_attribution_label_inProviderBlock(contextFalse), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.google_provider_config_plugin_framework.default", "add_terraform_attribution_label", "false"), | ||
), | ||
}, | ||
{ | ||
Config: testAccFwProvider_add_terraform_attribution_label_inProviderBlock(contextTrue), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.google_provider_config_plugin_framework.default", "add_terraform_attribution_label", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccFwProvider_add_terraform_attribution_label_defaultValue(t *testing.T) { | ||
acctest.SkipIfVcr(t) // Test doesn't interact with API | ||
|
||
context := map[string]interface{}{} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
// No PreCheck for checking ENVs | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccFwProvider_add_terraform_attribution_label_inEnvsOnly(context), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckNoResourceAttr("data.google_provider_config_plugin_framework.default", "add_terraform_attribution_label"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
// testAccFwProvider_add_terraform_attribution_label_inProviderBlock allows setting the add_terraform_attribution_label argument in a provider block. | ||
func testAccFwProvider_add_terraform_attribution_label_inProviderBlock(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
provider "google" { | ||
add_terraform_attribution_label = "%{add_terraform_attribution_label}" | ||
} | ||
data "google_provider_config_plugin_framework" "default" {} | ||
`, context) | ||
} | ||
|
||
// testAccFwProvider_add_terraform_attribution_label_inEnvsOnly allows testing when the add_terraform_attribution_label argument | ||
// is only supplied via ENVs | ||
func testAccFwProvider_add_terraform_attribution_label_inEnvsOnly(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
data "google_provider_config_plugin_framework" "default" {} | ||
`, context) | ||
} |
98 changes: 98 additions & 0 deletions
98
...aform/fwprovider/framework_provider_terraform_attribution_label_addition_strategy_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package fwprovider_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
) | ||
|
||
// TestAccFwProvider_terraform_attribution_label_addition_strategy is a series of acc tests asserting how the plugin-framework provider handles terraform_attribution_label_addition_strategy arguments | ||
// It is plugin-framework specific because the HCL used provisions plugin-framework-implemented resources | ||
// It is a counterpart to TestAccSdkProvider_terraform_attribution_label_addition_strategy | ||
func TestAccFwProvider_terraform_attribution_label_addition_strategy(t *testing.T) { | ||
testCases := map[string]func(t *testing.T){ | ||
// Configuring the provider using inputs | ||
"config sets terraform_attribution_label_addition_strategy values": testAccFwProvider_terraform_attribution_label_addition_strategy_configUsed, | ||
"when terraform_attribution_label_addition_strategy is unset in the config, the default value'CREATION_ONLY' is NOT set in the provider meta data": testAccFwProvider_terraform_attribution_label_addition_strategy_defaultValue, | ||
} | ||
|
||
for name, tc := range testCases { | ||
// shadow the tc variable into scope so that when | ||
// the loop continues, if t.Run hasn't executed tc(t) | ||
// yet, we don't have a race condition | ||
// see https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables | ||
tc := tc | ||
t.Run(name, func(t *testing.T) { | ||
tc(t) | ||
}) | ||
} | ||
} | ||
|
||
func testAccFwProvider_terraform_attribution_label_addition_strategy_configUsed(t *testing.T) { | ||
acctest.SkipIfVcr(t) // Test doesn't interact with API | ||
|
||
context1 := map[string]interface{}{ | ||
"terraform_attribution_label_addition_strategy": "CREATION_ONLY", | ||
} | ||
context2 := map[string]interface{}{ | ||
"terraform_attribution_label_addition_strategy": "PROACTIVE", | ||
} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
// No PreCheck for checking ENVs | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccFwProvider_terraform_attribution_label_addition_strategy_inProviderBlock(context1), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.google_provider_config_plugin_framework.default", "terraform_attribution_label_addition_strategy", "CREATION_ONLY"), | ||
), | ||
}, | ||
{ | ||
Config: testAccFwProvider_terraform_attribution_label_addition_strategy_inProviderBlock(context2), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.google_provider_config_plugin_framework.default", "terraform_attribution_label_addition_strategy", "PROACTIVE"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccFwProvider_terraform_attribution_label_addition_strategy_defaultValue(t *testing.T) { | ||
acctest.SkipIfVcr(t) // Test doesn't interact with API | ||
|
||
context := map[string]interface{}{} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
// No PreCheck for checking ENVs | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccFwProvider_terraform_attribution_label_addition_strategy_inEnvsOnly(context), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckNoResourceAttr("data.google_provider_config_plugin_framework.default", "terraform_attribution_label_addition_strategy"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
// testAccFwProvider_terraform_attribution_label_addition_strategy_inProviderBlock allows setting the terraform_attribution_label_addition_strategy argument in a provider block. | ||
func testAccFwProvider_terraform_attribution_label_addition_strategy_inProviderBlock(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
provider "google" { | ||
terraform_attribution_label_addition_strategy = "%{terraform_attribution_label_addition_strategy}" | ||
} | ||
data "google_provider_config_plugin_framework" "default" {} | ||
`, context) | ||
} | ||
|
||
// testAccFwProvider_terraform_attribution_label_addition_strategy_inEnvsOnly allows testing when the terraform_attribution_label_addition_strategy argument | ||
// is only supplied via ENVs | ||
func testAccFwProvider_terraform_attribution_label_addition_strategy_inEnvsOnly(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
data "google_provider_config_plugin_framework" "default" {} | ||
`, context) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
mmv1/third_party/terraform/provider/provider_add_terraform_attribution_label_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package provider_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
) | ||
|
||
// TestAccSdkProvider_add_terraform_attribution_label is a series of acc tests asserting how the plugin-framework provider handles add_terraform_attribution_label arguments | ||
// It is plugin-framework specific because the HCL used provisions plugin-framework-implemented resources | ||
// It is a counterpart to TestAccFwProvider_add_terraform_attribution_label | ||
func TestAccSdkProvider_add_terraform_attribution_label(t *testing.T) { | ||
testCases := map[string]func(t *testing.T){ | ||
// Configuring the provider using inputs | ||
"config sets add_terraform_attribution_label values": testAccSdkProvider_add_terraform_attribution_label_configUsed, | ||
"when add_terraform_attribution_label is unset in the config, the default value 'true' is set in the provider meta data": testAccSdkProvider_add_terraform_attribution_label_defaultValue, | ||
} | ||
|
||
for name, tc := range testCases { | ||
// shadow the tc variable into scope so that when | ||
// the loop continues, if t.Run hasn't executed tc(t) | ||
// yet, we don't have a race condition | ||
// see https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables | ||
tc := tc | ||
t.Run(name, func(t *testing.T) { | ||
tc(t) | ||
}) | ||
} | ||
} | ||
|
||
func testAccSdkProvider_add_terraform_attribution_label_configUsed(t *testing.T) { | ||
acctest.SkipIfVcr(t) // Test doesn't interact with API | ||
|
||
contextFalse := map[string]interface{}{ | ||
"add_terraform_attribution_label": "false", | ||
} | ||
contextTrue := map[string]interface{}{ | ||
"add_terraform_attribution_label": "true", | ||
} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
// No PreCheck for checking ENVs | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccSdkProvider_add_terraform_attribution_label_inProviderBlock(contextFalse), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.google_provider_config_sdk.default", "add_terraform_attribution_label", "false"), | ||
), | ||
}, | ||
{ | ||
Config: testAccSdkProvider_add_terraform_attribution_label_inProviderBlock(contextTrue), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.google_provider_config_sdk.default", "add_terraform_attribution_label", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccSdkProvider_add_terraform_attribution_label_defaultValue(t *testing.T) { | ||
acctest.SkipIfVcr(t) // Test doesn't interact with API | ||
|
||
context := map[string]interface{}{} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
// No PreCheck for checking ENVs | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccSdkProvider_add_terraform_attribution_label_inEnvsOnly(context), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.google_provider_config_sdk.default", "add_terraform_attribution_label", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
// testAccSdkProvider_add_terraform_attribution_label_inProviderBlock allows setting the add_terraform_attribution_label argument in a provider block. | ||
func testAccSdkProvider_add_terraform_attribution_label_inProviderBlock(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
provider "google" { | ||
add_terraform_attribution_label = "%{add_terraform_attribution_label}" | ||
} | ||
data "google_provider_config_sdk" "default" {} | ||
`, context) | ||
} | ||
|
||
// testAccSdkProvider_add_terraform_attribution_label_inEnvsOnly allows testing when the add_terraform_attribution_label argument | ||
// is only supplied via ENVs | ||
func testAccSdkProvider_add_terraform_attribution_label_inEnvsOnly(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
data "google_provider_config_sdk" "default" {} | ||
`, context) | ||
} |
Oops, something went wrong.