Skip to content

Commit

Permalink
Remove plugin-framework test `TestFrameworkProvider_LoadAndValidateFr…
Browse files Browse the repository at this point in the history
…amework_billingProject`
  • Loading branch information
SarahFrench committed Sep 2, 2024
1 parent 7af8c56 commit 05841af
Showing 1 changed file with 0 additions and 105 deletions.
105 changes: 0 additions & 105 deletions mmv1/third_party/terraform/fwtransport/go/framework_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,111 +234,6 @@ func TestFrameworkProvider_LoadAndValidateFramework_project(t *testing.T) {
// })
// }

func TestFrameworkProvider_LoadAndValidateFramework_billingProject(t *testing.T) {

// Note: In the test function we need to set the below fields in test case's fwmodels.ProviderModel value
// this is to stop the code under test experiencing errors, and could be addressed in future refactoring.
// - Credentials: If we don't set this then the test looks for application default credentials and can fail depending on the machine running the test
// - ImpersonateServiceAccountDelegates: If we don't set this, we get a nil pointer exception ¯\_(ツ)_/¯

cases := map[string]struct {
ConfigValues fwmodels.ProviderModel
EnvVariables map[string]string
ExpectedDataModelValue basetypes.StringValue
ExpectedConfigStructValue basetypes.StringValue
ExpectError bool
}{
"billing_project value set in the provider schema is not overridden by environment variables": {
ConfigValues: fwmodels.ProviderModel{
BillingProject: types.StringValue("billing-project-from-config"),
},
EnvVariables: map[string]string{
"GOOGLE_BILLING_PROJECT": "billing-project-from-env",
},
ExpectedDataModelValue: types.StringValue("billing-project-from-config"),
ExpectedConfigStructValue: types.StringValue("billing-project-from-config"),
},
"billing_project can be set by environment variable, when no value supplied via the config": {
ConfigValues: fwmodels.ProviderModel{
BillingProject: types.StringNull(),
},
EnvVariables: map[string]string{
"GOOGLE_BILLING_PROJECT": "billing-project-from-env",
},
ExpectedDataModelValue: types.StringValue("billing-project-from-env"),
ExpectedConfigStructValue: types.StringValue("billing-project-from-env"),
},
"when no billing_project values are provided via config or environment variables, the field remains unset without error": {
ConfigValues: fwmodels.ProviderModel{
BillingProject: types.StringNull(),
},
ExpectedDataModelValue: types.StringNull(),
ExpectedConfigStructValue: types.StringNull(),
},
// Handling empty strings in config
"when billing_project is set as an empty string the empty string is used and not ignored": {
ConfigValues: fwmodels.ProviderModel{
BillingProject: types.StringValue(""),
},
ExpectedDataModelValue: types.StringValue(""),
ExpectedConfigStructValue: types.StringValue(""),
},
"when billing_project is set as an empty string, the empty string is not ignored in favor of an environment variable": {
ConfigValues: fwmodels.ProviderModel{
BillingProject: types.StringValue(""),
},
EnvVariables: map[string]string{
"GOOGLE_BILLING_PROJECT": "billing-project-from-env",
},
ExpectedDataModelValue: types.StringValue(""),
ExpectedConfigStructValue: types.StringValue(""),
},
}

for tn, tc := range cases {
t.Run(tn, func(t *testing.T) {

// Arrange
acctest.UnsetTestProviderConfigEnvs(t)
acctest.SetupTestEnvs(t, tc.EnvVariables)

ctx := context.Background()
tfVersion := "foobar"
providerversion := "999"
diags := diag.Diagnostics{}
data := tc.ConfigValues
data.Credentials = types.StringValue(transport_tpg.TestFakeCredentialsPath)
impersonateServiceAccountDelegates, _ := types.ListValue(types.StringType, []attr.Value{}) // empty list
data.ImpersonateServiceAccountDelegates = impersonateServiceAccountDelegates

p := fwtransport.FrameworkProviderConfig{}

// Act
p.LoadAndValidateFramework(ctx, &data, tfVersion, &diags, providerversion)

// Assert
if diags.HasError() && tc.ExpectError {
return
}
if diags.HasError() && !tc.ExpectError {
for i, err := range diags.Errors() {
num := i + 1
t.Logf("unexpected error #%d : %s : %s", num, err.Summary(), err.Detail())
}
t.Fatalf("did not expect error, but [%d] error(s) occurred", diags.ErrorsCount())
}
// Checking mutation of the data model
if !data.BillingProject.Equal(tc.ExpectedDataModelValue) {
t.Fatalf("want billing_project in the `fwmodels.ProviderModel` struct to be `%s`, but got the value `%s`", tc.ExpectedDataModelValue, data.BillingProject.String())
}
// Checking the value passed to the config structs
if !p.BillingProject.Equal(tc.ExpectedConfigStructValue) {
t.Fatalf("want billing_project in the `FrameworkProviderConfig` struct to be `%s`, but got the value `%s`", tc.ExpectedConfigStructValue, p.BillingProject.String())
}
})
}
}

func TestFrameworkProvider_LoadAndValidateFramework_region(t *testing.T) {

// Note: In the test function we need to set the below fields in test case's fwmodels.ProviderModel value
Expand Down

0 comments on commit 05841af

Please sign in to comment.