Skip to content

Commit

Permalink
Add test cases covering default values used when there's no input
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahFrench committed Sep 27, 2024
1 parent 8cc3271 commit 64fca87
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func TestAccFwProvider_request_timeout(t *testing.T) {
testCases := map[string]func(t *testing.T){
// Configuring the provider using inputs
"a default value of 120s is used when there are no user inputs": testAccFwProvider_request_timeout_providerDefault,
"request_timeout can be set in config in different formats, are NOT normalized to full-length format": testAccFwProvider_request_timeout_setInConfig,
//no ENVs to test

Expand All @@ -36,6 +37,25 @@ func TestAccFwProvider_request_timeout(t *testing.T) {
}
}

func testAccFwProvider_request_timeout_providerDefault(t *testing.T) {
acctest.SkipIfVcr(t) // Test doesn't interact with API

defaultValue := "120s"

acctest.VcrTest(t, resource.TestCase{
// No PreCheck for checking ENVs
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccFwProvider_request_timeout_unset(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.google_provider_config_plugin_framework.default", "request_timeout", defaultValue),
),
},
},
})
}

func testAccFwProvider_request_timeout_setInConfig(t *testing.T) {
acctest.SkipIfVcr(t) // Test doesn't interact with API

Expand Down Expand Up @@ -103,3 +123,10 @@ provider "google" {
data "google_provider_config_plugin_framework" "default" {}
`, context)
}

// testAccFwProvider_request_timeout_inEnvsOnly allows testing when the request_timeout argument is not set
func testAccFwProvider_request_timeout_unset() string {
return `
data "google_provider_config_plugin_framework" "default" {}
`
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func TestAccSdkProvider_request_timeout(t *testing.T) {
testCases := map[string]func(t *testing.T){
// Configuring the provider using inputs
"a default value of 0s is used when there are no user inputs (it is overridden downstream)": testAccSdkProvider_request_timeout_providerDefault,
"request_timeout can be set in config in different formats, are normalized to full-length format": testAccSdkProvider_request_timeout_setInConfig,
//no ENVs to test

Expand All @@ -36,6 +37,23 @@ func TestAccSdkProvider_request_timeout(t *testing.T) {
}
}

func testAccSdkProvider_request_timeout_providerDefault(t *testing.T) {
acctest.SkipIfVcr(t) // Test doesn't interact with API

acctest.VcrTest(t, resource.TestCase{
// No PreCheck for checking ENVs
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
Steps: []resource.TestStep{
{
Config: testAccSdkProvider_request_timeout_unset(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.google_provider_config_sdk.default", "request_timeout", "0s"),
),
},
},
})
}

func testAccSdkProvider_request_timeout_setInConfig(t *testing.T) {
acctest.SkipIfVcr(t) // Test doesn't interact with API

Expand Down Expand Up @@ -100,3 +118,10 @@ provider "google" {
data "google_provider_config_sdk" "default" {}
`, context)
}

// testAccSdkProvider_request_timeout_inEnvsOnly allows testing when the request_timeout argument is not set
func testAccSdkProvider_request_timeout_unset() string {
return `
data "google_provider_config_sdk" "default" {}
`
}

0 comments on commit 64fca87

Please sign in to comment.