diff --git a/internal/service/advancedclustertpf/resource_compatibility_reuse.go b/internal/service/advancedclustertpf/resource_compatibility_reuse.go index 8cd025ae5f..0f0bb3c172 100644 --- a/internal/service/advancedclustertpf/resource_compatibility_reuse.go +++ b/internal/service/advancedclustertpf/resource_compatibility_reuse.go @@ -19,9 +19,11 @@ func FormatMongoDBMajorVersion(version string) string { func getReplicationSpecIDsFromOldAPI(ctx context.Context, projectID, clusterName string, api admin20240530.ClustersApi) (map[string]string, error) { clusterOldAPI, _, err := api.GetCluster(ctx, projectID, clusterName).Execute() - if apiError, ok := admin20240530.AsError(err); ok { - if apiError.GetErrorCode() == "ASYMMETRIC_SHARD_UNSUPPORTED" { - return nil, nil // if its the case of an asymmetric shard an error is expected in old API, replication_specs.*.id attribute will not be populated + if err != nil { + if apiError, ok := admin20240530.AsError(err); ok { + if apiError.GetErrorCode() == "ASYMMETRIC_SHARD_UNSUPPORTED" { + return nil, nil // if its the case of an asymmetric shard an error is expected in old API, replication_specs.*.id attribute will not be populated + } } return nil, fmt.Errorf("error reading advanced cluster with 2023-02-01 API (%s): %s", clusterName, err) } diff --git a/internal/service/advancedclustertpf/resource_compatiblity.go b/internal/service/advancedclustertpf/resource_compatiblity.go index 137a1e6c36..5478180970 100644 --- a/internal/service/advancedclustertpf/resource_compatiblity.go +++ b/internal/service/advancedclustertpf/resource_compatiblity.go @@ -64,7 +64,7 @@ func normalizeFromTFModel(ctx context.Context, model *TFModel, diags *diag.Diagn if diags.HasError() { return nil } - usingLegacySchema := numShardsGt1(counts) + usingLegacySchema := isNumShardsGreaterThanOne(counts) if usingLegacySchema && shoudlExplodeNumShards { explodeNumShards(latestModel, counts) } @@ -149,7 +149,7 @@ func usingLegacySchema(ctx context.Context, input types.List, diags *diag.Diagno if diags.HasError() { return false } - return numShardsGt1(counts) + return isNumShardsGreaterThanOne(counts) } func numShardsMap(ctx context.Context, input types.List, diags *diag.Diagnostics) map[string]int64 { @@ -166,7 +166,7 @@ func numShardsMap(ctx context.Context, input types.List, diags *diag.Diagnostics return counts } -func numShardsGt1(counts []int64) bool { +func isNumShardsGreaterThanOne(counts []int64) bool { for _, count := range counts { if count > 1 { return true diff --git a/internal/testutil/unit/http_mocker.go b/internal/testutil/unit/http_mocker.go index 9413e9f4a9..5cbe053a46 100644 --- a/internal/testutil/unit/http_mocker.go +++ b/internal/testutil/unit/http_mocker.go @@ -95,8 +95,7 @@ func MockTestCaseAndRun(t *testing.T, vars map[string]string, config *MockHTTPDa stepCount := len(testCase.Steps) for i := range stepCount - 1 { step := &testCase.Steps[i] - oldCheck := step.Check - if oldCheck != nil { + if oldCheck := step.Check; oldCheck != nil { step.Check = resource.ComposeAggregateTestCheckFunc(oldCheck, checkFunc) } } @@ -104,8 +103,7 @@ func MockTestCaseAndRun(t *testing.T, vars map[string]string, config *MockHTTPDa oldCheckDestroy := testCase.CheckDestroy newCheckDestroy := func(s *terraform.State) error { if oldCheckDestroy != nil { - err := oldCheckDestroy(s) - if err != nil { + if err := oldCheckDestroy(s); err != nil { return err } }