Skip to content

Commit

Permalink
test: Refactor tests for mongodb_advanced_cluster covering transiti…
Browse files Browse the repository at this point in the history
…ons to auto-scaling mode (#2863)

* refactor tests

* cover geo sharded case

* temp: change to run tests in CI
  • Loading branch information
oarbusi authored Dec 9, 2024
1 parent 4a42192 commit 3cb08c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1346,5 +1346,6 @@ func waitForUpdateToFinish(ctx context.Context, connV2 *admin.APIClient, project
}

_, err := stateConf.WaitForStateContext(ctx)

return err
}
66 changes: 15 additions & 51 deletions internal/service/advancedcluster/resource_advanced_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,15 @@ func symmetricGeoShardedOldSchemaTestCase(t *testing.T) resource.TestCase {
Steps: []resource.TestStep{
{
Config: configGeoShardedOldSchema(orgID, projectName, clusterName, 2, 2, false),
Check: checkGeoShardedOldSchema(clusterName, 2, 2, true, false),
Check: resource.ComposeAggregateTestCheckFunc(
checkGeoShardedOldSchema(clusterName, 2, 2, true, false),
checkIndependentShardScalingMode(clusterName, "CLUSTER")),
},
{
Config: configGeoShardedOldSchema(orgID, projectName, clusterName, 3, 3, false),
Check: checkGeoShardedOldSchema(clusterName, 3, 3, true, false),
Check: resource.ComposeAggregateTestCheckFunc(
checkGeoShardedOldSchema(clusterName, 3, 3, true, false),
checkIndependentShardScalingMode(clusterName, "CLUSTER")),
},
},
}
Expand Down Expand Up @@ -720,7 +724,9 @@ func asymmetricShardedNewSchemaTestCase(t *testing.T) resource.TestCase {
Steps: []resource.TestStep{
{
Config: configShardedNewSchema(orgID, projectName, clusterName, 50, "M30", "M40", admin.PtrInt(2000), admin.PtrInt(2500), false),
Check: checkShardedNewSchema(50, "M30", "M40", admin.PtrInt(2000), admin.PtrInt(2500), true, false),
Check: resource.ComposeAggregateTestCheckFunc(
checkShardedNewSchema(50, "M30", "M40", admin.PtrInt(2000), admin.PtrInt(2500), true, false),
checkIndependentShardScalingMode(clusterName, "SHARD")),
},
},
}
Expand Down Expand Up @@ -770,11 +776,15 @@ func TestAccClusterAdvancedClusterConfig_shardedTransitionFromOldToNewSchema(t *
Steps: []resource.TestStep{
{
Config: configShardedTransitionOldToNewSchema(orgID, projectName, clusterName, false, false),
Check: checkShardedTransitionOldToNewSchema(false),
Check: resource.ComposeAggregateTestCheckFunc(
checkShardedTransitionOldToNewSchema(false),
checkIndependentShardScalingMode(clusterName, "CLUSTER")),
},
{
Config: configShardedTransitionOldToNewSchema(orgID, projectName, clusterName, true, false),
Check: checkShardedTransitionOldToNewSchema(true),
Check: resource.ComposeAggregateTestCheckFunc(
checkShardedTransitionOldToNewSchema(true),
checkIndependentShardScalingMode(clusterName, "CLUSTER")),
},
},
})
Expand Down Expand Up @@ -927,31 +937,6 @@ func TestAccClusterAdvancedCluster_priorityNewSchema(t *testing.T) {
})
}

func TestAccAdvancedCluster_oldToNewSchemaWithAutoscalingDisabled(t *testing.T) {
acc.SkipIfTPFAdvancedCluster(t)
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
clusterName = acc.RandomClusterName()
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: acc.PreCheckBasicSleep(t, nil, orgID, projectName),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Config: configShardedTransitionOldToNewSchema(orgID, projectName, clusterName, false, false),
Check: checkIndependentShardScalingMode(clusterName, "CLUSTER"),
},
{
Config: configShardedTransitionOldToNewSchema(orgID, projectName, clusterName, true, false),
Check: checkIndependentShardScalingMode(clusterName, "CLUSTER"),
},
},
})
}

func TestAccAdvancedCluster_oldToNewSchemaWithAutoscalingEnabled(t *testing.T) {
acc.SkipIfTPFAdvancedCluster(t)
var (
Expand Down Expand Up @@ -1006,27 +991,6 @@ func TestAccAdvancedCluster_oldToNewSchemaWithAutoscalingDisabledToEnabled(t *te
})
}

func TestAccAdvancedCluster_newSchema(t *testing.T) {
acc.SkipIfTPFAdvancedCluster(t)
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
clusterName = acc.RandomClusterName()
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: acc.PreCheckBasicSleep(t, nil, orgID, projectName),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Config: configShardedTransitionOldToNewSchema(orgID, projectName, clusterName, true, false),
Check: checkIndependentShardScalingMode(clusterName, "SHARD"),
},
},
})
}

func checkIndependentShardScalingMode(clusterName, expectedMode string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down

0 comments on commit 3cb08c3

Please sign in to comment.