-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial version of a plugin-framework provider config test, move …
…code between packages to allow tests (#8797) (#6180) * Add initial version of plugin framework provider config test affected by inaccessible functions * Move `ReplaceVarsForFrameworkTest` to `fwresource` package This mirrors how old, ReplaceVars* functions are in the `tpgresource` package * Move functions for changing ENVs in tests to `acctest` package, update usage * Move `GenerateFakeCredentialsJson` function to `acctest` package, update usage * Refactor provider config tests to use plugin-framework types * Add all test cases to match equivalent SDK provider config tests Some test cases currently fail due to different handling of empty values by the SDK and plugin framework * Add test case about handling of Unknown values for `project` * Update tests to check values in BOTH the data model and provider config struct after `LoadAndValidateFramework` runs Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
d005f34
commit ac37ec7
Showing
8 changed files
with
152 additions
and
148 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:none | ||
|
||
``` |
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
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ import ( | |
"github.com/hashicorp/terraform-plugin-mux/tf5muxserver" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar" | ||
) | ||
|
||
func CheckDataSourceStateMatchesResourceState(dataSourceName, resourceName string) func(*terraform.State) error { | ||
|
@@ -202,3 +203,56 @@ func CreateZIPArchiveForCloudFunctionSource(t *testing.T, sourcePath string) str | |
} | ||
return tmpfile.Name() | ||
} | ||
|
||
// providerConfigEnvNames returns a list of all the environment variables that could be set by a user to configure the provider | ||
func providerConfigEnvNames() []string { | ||
|
||
envs := []string{} | ||
|
||
// Use existing collections of ENV names | ||
envVarsSets := [][]string{ | ||
envvar.CredsEnvVars, // credentials field | ||
envvar.ProjectEnvVars, // project field | ||
envvar.RegionEnvVars, //region field | ||
envvar.ZoneEnvVars, // zone field | ||
} | ||
for _, set := range envVarsSets { | ||
envs = append(envs, set...) | ||
} | ||
|
||
// Add remaining ENVs | ||
envs = append(envs, "GOOGLE_OAUTH_ACCESS_TOKEN") // access_token field | ||
envs = append(envs, "GOOGLE_BILLING_PROJECT") // billing_project field | ||
envs = append(envs, "GOOGLE_IMPERSONATE_SERVICE_ACCOUNT") // impersonate_service_account field | ||
envs = append(envs, "USER_PROJECT_OVERRIDE") // user_project_override field | ||
envs = append(envs, "CLOUDSDK_CORE_REQUEST_REASON") // request_reason field | ||
|
||
return envs | ||
} | ||
|
||
// UnsetProviderConfigEnvs unsets any ENVs in the test environment that | ||
// configure the provider. | ||
// The testing package will restore the original values after the test | ||
func UnsetTestProviderConfigEnvs(t *testing.T) { | ||
envs := providerConfigEnvNames() | ||
if len(envs) > 0 { | ||
for _, k := range envs { | ||
t.Setenv(k, "") | ||
} | ||
} | ||
} | ||
|
||
func SetupTestEnvs(t *testing.T, envValues map[string]string) { | ||
// Set ENVs | ||
if len(envValues) > 0 { | ||
for k, v := range envValues { | ||
t.Setenv(k, v) | ||
} | ||
} | ||
} | ||
|
||
// Returns a fake credentials JSON string with the client_email set to a test-specific value | ||
func GenerateFakeCredentialsJson(testId string) string { | ||
json := fmt.Sprintf(`{"private_key_id": "foo","private_key": "bar","client_email": "%[email protected]","client_id": "[email protected]","type": "service_account"}`, testId) | ||
return json | ||
} |
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
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
Oops, something went wrong.