Skip to content

Commit

Permalink
Add SDK provider configuration tests, part 2 (GoogleCloudPlatform#7723)
Browse files Browse the repository at this point in the history
* Add tests for `providerConfigure` testing `billing_project` config

* Fix `billing_project` test

* Add tests for `providerConfigure` testing `region` config

* Add tests for `providerConfigure` testing `zone` config

* Add tests for `providerConfigure` testing `user_project_override` config

* Remove old redundant `TestHandleSDKDefaults_*` tests

* Update code following creation of `transport` package

* Reposition `transport_tpg` in imports

* Add WIP of scopes test

* Fix defect in test case

* Fix scopes test

* Implement test cases for user config including zero values, and update tests to asset when field should be unset but is found in config

* Make test error messages clearer w.r.t provider config from user versus derived Config struct

* Fix import issue after rebase

* Add comments separating types of test case, add cases for empty strings overwritten by ENVs

* Rebase PR to pull in changes, including service package split

* Add test cases that show empty strings are ignored and ENVs are used instead

* Update text in test failure messages, add comments to signpost different types of test case

* Make lack of error more explicit in test case

* Fix import issues from rebasing branch

* update use of `ioutil` to `os`

* Make imports match what's on main

* Update `testFakeCredentialsPath` to `transport_tpg.TestFakeCredentialsPath`

* Add missing comma

* Move file into `provider_test` package, update imports and remove duplicate code

* Fix defect when trying to access `CredentialsFromJSON` function

* Add missing function calls to set ENVs used in tests

* Update tests for region field, add test case for use of self links

* Aad test case for zone field, self links are not shortened and usable

* Remove test case; `ConflictsWith` on fields not testable at this level

* Update test case names, add comments
  • Loading branch information
SarahFrench authored and nevzheng committed Aug 25, 2023
1 parent e729ae5 commit 0401cbb
Show file tree
Hide file tree
Showing 3 changed files with 789 additions and 451 deletions.
8 changes: 4 additions & 4 deletions mmv1/third_party/terraform/provider/provider.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func Provider() *schema.Provider {
"credentials": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCredentials,
ValidateFunc: ValidateCredentials,
ConflictsWith: []string{"access_token"},
},

Expand Down Expand Up @@ -183,7 +183,7 @@ func Provider() *schema.Provider {
}

provider.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
return providerConfigure(ctx, d, provider)
return ProviderConfigure(ctx, d, provider)
}

transport_tpg.ConfigureDCLProvider(provider)
Expand Down Expand Up @@ -632,7 +632,7 @@ end # products.each do
)
}

func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Provider) (interface{}, diag.Diagnostics) {
func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Provider) (interface{}, diag.Diagnostics) {
err := transport_tpg.HandleSDKDefaults(d)
if err != nil {
return nil, diag.FromErr(err)
Expand Down Expand Up @@ -758,7 +758,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
return transport_tpg.ProviderDCLConfigure(d, &config), nil
}

func validateCredentials(v interface{}, k string) (warnings []string, errors []error) {
func ValidateCredentials(v interface{}, k string) (warnings []string, errors []error) {
if v == nil || v.(string) == "" {
return
}
Expand Down
Loading

0 comments on commit 0401cbb

Please sign in to comment.