Skip to content

Commit

Permalink
Resolve 4.0 TODOs for provider.go (#28529)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattfry authored Jan 16, 2025
1 parent f54480d commit 8e507e1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 63 deletions.
27 changes: 19 additions & 8 deletions internal/provider/framework/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ func Test_getOidcToken(t *testing.T) {

if result == nil {
t.Fatalf("getOidcToken returned nil result without an error")
} else if *result != expectedString {
}

if *result != expectedString {
t.Fatalf("getOidcToken did not return expected string (%s), got %+v", expectedString, *result)
}
}
Expand All @@ -41,7 +43,9 @@ func Test_getOidcTokenFromFile(t *testing.T) {

if result == nil {
t.Fatalf("getOidcToken returned nil result without an error")
} else if *result != expectedString {
}

if *result != expectedString {
t.Fatalf("getOidcToken did not return expected string `%s`, got `%s`", expectedString, *result)
}
}
Expand Down Expand Up @@ -113,7 +117,8 @@ func Test_getClientSecret(t *testing.T) {
}
if result == nil {
t.Fatalf("getClientSecret returned nil result without an error")
} else if *result != expectedString {
}
if *result != expectedString {
t.Fatalf("getCLientSecret did not return expected string `%s`, got `%s`", expectedString, *result)
}
}
Expand Down Expand Up @@ -147,7 +152,8 @@ func Test_getClientSecretFromFile(t *testing.T) {
}
if result == nil {
t.Fatalf("getClientSecretFromFile returned nil result without an error")
} else if *result != expectedString {
}
if *result != expectedString {
t.Fatalf("getClientSecret did not return expected string `%s`, got `%s`", expectedString, *result)
}
}
Expand Down Expand Up @@ -179,7 +185,8 @@ func Test_getClientID(t *testing.T) {
}
if result == nil {
t.Fatalf("getClientID returned nil result without an error")
} else if *result != expectedString {
}
if *result != expectedString {
t.Fatalf("getClientID did not return expected string `%s`, got `%s`", expectedString, *result)
}
}
Expand Down Expand Up @@ -211,7 +218,8 @@ func Test_getClientIDFromFile(t *testing.T) {
}
if result == nil {
t.Fatalf("getClientID returned nil result without an error")
} else if *result != expectedString {
}
if *result != expectedString {
t.Fatalf("getClientID did not return expected string `%s`, got `%s`", expectedString, *result)
}
}
Expand All @@ -230,7 +238,8 @@ func Test_getClientIDAKSWorkload(t *testing.T) {
}
if result == nil {
t.Fatalf("getClientID returned nil result without an error")
} else if *result != expectedString {
}
if *result != expectedString {
t.Fatalf("getClientID did not return expected string `%s`, got `%s`", expectedString, *result)
}
}
Expand Down Expand Up @@ -261,7 +270,9 @@ func Test_decodeCertificate(t *testing.T) {
if err != nil {
t.Fatalf("decodeCertificate returned unexpected error %v", err)
}

if result == nil {
t.Fatalf("decodeCertificate returned nil result without an error")
}
if string(result) != expected {
t.Fatalf("decodeCertificate did not return expected result `%s`, got `%s`", expected, result)
}
Expand Down
6 changes: 1 addition & 5 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureContextFunc {
// buildClient is used to configure behavioral aspects of the provider. To configure the
// cloud environment and authentication-related settings, use the providerConfigure function.
func buildClient(ctx context.Context, p *schema.Provider, d *schema.ResourceData, authConfig *auth.Credentials) (*clients.Client, diag.Diagnostics) {
// TODO: This hardcoded default is for v3.x, where `resource_provider_registrations` is not defined. Remove this hardcoded default in v4.0
providerRegistrations := resourceproviders.ProviderRegistrationsLegacy
if features.FourPointOhBeta() {
providerRegistrations = d.Get("resource_provider_registrations").(string)
}
providerRegistrations := d.Get("resource_provider_registrations").(string)

// TODO: Remove in v5.0
if d.Get("skip_provider_registration").(bool) {
Expand Down
50 changes: 0 additions & 50 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,60 +328,10 @@ func TestAccProvider_resourceProviders_explicit(t *testing.T) {
}

func TestAccProvider_cliAuth(t *testing.T) {
// TODO: remove this test in v4.0
if features.FourPointOhBeta() {
t.Skip("skipping 3.x specific test")
}

if os.Getenv("TF_ACC") == "" {
t.Skip("TF_ACC not set")
}

logging.SetOutput(t)

provider := TestAzureProvider()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

// Support only Azure CLI authentication
provider.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
envName := d.Get("environment").(string)
env, err := environments.FromName(envName)
if err != nil {
t.Fatalf("configuring environment %q: %v", envName, err)
}

authConfig := &auth.Credentials{
Environment: *env,
EnableAuthenticatingUsingAzureCLI: true,
}

return buildClient(ctx, provider, d, authConfig)
}

d := provider.Configure(ctx, terraform.NewResourceConfigRaw(nil))
if d != nil && d.HasError() {
t.Fatalf("err: %+v", d)
}

if errs := testCheckProvider(provider); len(errs) > 0 {
for _, err := range errs {
t.Error(err)
}
}
}

// TODO: remove TestAccProvider_cliAuth and rename this test to TestAccProvider_cliAuth in v4.0
func TestAccProvider_cliAuthWithSubscriptionIdHint(t *testing.T) {
if os.Getenv("TF_ACC") == "" {
t.Skip("TF_ACC not set")
}

// TODO: remove this condition in v4.0
if os.Getenv("ARM_SUBSCRIPTION_ID") == "" {
t.Skip("ARM_SUBSCRIPTION_ID not set")
}

logging.SetOutput(t)

provider := TestAzureProvider()
Expand Down

0 comments on commit 8e507e1

Please sign in to comment.