Skip to content

Commit

Permalink
address PR comments 2
Browse files Browse the repository at this point in the history
  • Loading branch information
EspenAlbert committed Dec 2, 2024
1 parent 4f65aac commit 2b6c361
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/service/advancedclustertpf/resource_compatiblity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions internal/testutil/unit/http_mocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,15 @@ 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)
}
}
// Using CheckDestroy for the final step assertions to allow mocked responses in cleanup
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
}
}
Expand Down

0 comments on commit 2b6c361

Please sign in to comment.