Skip to content

Commit

Permalink
test: Refactor migration tests to use utility function and cover migr…
Browse files Browse the repository at this point in the history
…ation scenarios coming from 1.17.5 (#2481)

* refactor migration test and define scenarios for updating and transitioning after upgrade

* fix check of external id in migration tests
  • Loading branch information
AgustinBettati authored Aug 7, 2024
1 parent 74ce676 commit 038ca26
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,135 +12,85 @@ import (
)

func TestMigAdvancedCluster_replicaSetAWSProvider(t *testing.T) {
var (
projectID = acc.ProjectIDExecution(t)
clusterName = acc.RandomClusterName()
config = configReplicaSetAWSProvider(projectID, clusterName, 60, 3)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: config,
Check: checkReplicaSetAWSProvider(projectID, clusterName, 60, 3, false, false),
},
mig.TestStepCheckEmptyPlan(config),
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: config,
Check: checkReplicaSetAWSProvider(projectID, clusterName, 60, 3, true, true), // external_id will be present in latest version
},
},
})
// once 1.18.0 is released we can adjust this to always check new attributes - CLOUDP-266096
testCase := replicaSetAWSProviderTestCase(t, false)
mig.CreateAndRunTest(t, &testCase)
}

func TestMigAdvancedCluster_replicaSetMultiCloud(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName() // No ProjectIDExecution to avoid cross-region limits because multi-region
clusterName = acc.RandomClusterName()
config = configReplicaSetMultiCloud(orgID, projectName, clusterName)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: config,
Check: checkReplicaSetMultiCloud(clusterName, 3, false),
},
mig.TestStepCheckEmptyPlan(config),
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: config,
Check: checkReplicaSetMultiCloud(clusterName, 3, true), // external_id will be present in latest version
},
},
})
// once 1.18.0 is released we can adjust this to always check new attributes - CLOUDP-266096
testCase := replicaSetMultiCloudTestCase(t, false)
mig.CreateAndRunTest(t, &testCase)
}

func TestMigAdvancedCluster_singleShardedMultiCloud(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName() // No ProjectIDExecution to avoid cross-region limits because multi-region
clusterName = acc.RandomClusterName()
config = configShardedMultiCloud(orgID, projectName, clusterName, 1, "M30")
)
// once 1.18.0 is released we can adjust this to always check new attributes - CLOUDP-266096
testCase := singleShardedMultiCloudTestCase(t, false)
mig.CreateAndRunTest(t, &testCase)
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: config,
Check: checkShardedMultiCloud(clusterName, 1, "M30", false),
},
mig.TestStepCheckEmptyPlan(config),
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: config,
Check: checkShardedMultiCloud(clusterName, 1, "M30", true), // external_id will be present in latest version
},
},
})
func TestMigAdvancedCluster_symmetricGeoShardedOldSchema(t *testing.T) {
// once 1.18.0 is released we can adjust this to always check new attributes - CLOUDP-266096
testCase := symmetricGeoShardedOldSchemaTestCase(t, false)
mig.CreateAndRunTest(t, &testCase)
}

func TestMigAdvancedCluster_asymmetricShardedNewSchema(t *testing.T) {
acc.SkipTestForCI(t) // latest release does not support ISS, to be adjusted in CLOUDP-266096
testCase := asymmetricShardedNewSchemaTestCase(t)
mig.CreateAndRunTest(t, &testCase)
}

func TestMigAdvancedCluster_singleShardPerZoneGeoSharded(t *testing.T) {
func TestMigAdvancedCluster_replicaSetAWSProviderUpdateAfterVerisonUpgrade(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName() // No ProjectIDExecution to avoid cross-region limits because multi-region
projectID = acc.ProjectIDExecution(t)
clusterName = acc.RandomClusterName()
config = configGeoShardedOldSchema(orgID, projectName, clusterName, 1, 1, false)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: config,
Check: checkGeoShardedOldSchema(clusterName, 1, 1, false, false),
ExternalProviders: acc.ExternalProviders("1.17.5"), // last version that did not support new sharding schema or attributes
Config: configReplicaSetAWSProvider(projectID, clusterName, 60, 3),
Check: checkReplicaSetAWSProvider(projectID, clusterName, 60, 3, false, false),
},
mig.TestStepCheckEmptyPlan(config),
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: config,
Check: checkGeoShardedOldSchema(clusterName, 1, 1, true, true), // external_id will be present in latest version
Config: configReplicaSetAWSProvider(projectID, clusterName, 60, 5),
Check: checkReplicaSetAWSProvider(projectID, clusterName, 60, 5, true, true),
},
},
})
}

func TestMigAdvancedCluster_symmetricGeoShardedOldSchema(t *testing.T) {
func TestMigAdvancedCluster_geoShardedOldSchemaUpdateAfterVerisonUpgrade(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName() // No ProjectIDExecution to avoid cross-region limits because multi-region
clusterName = acc.RandomClusterName()
config = configGeoShardedOldSchema(orgID, projectName, clusterName, 2, 2, false)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
Config: config,
ExternalProviders: acc.ExternalProviders("1.17.5"), // last version that did not support new sharding schema or attributes
Config: configGeoShardedOldSchema(orgID, projectName, clusterName, 2, 2, false),
Check: checkGeoShardedOldSchema(clusterName, 2, 2, false, false),
},
mig.TestStepCheckEmptyPlan(config),
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: configGeoShardedOldSchema(orgID, projectName, clusterName, 2, 1, false),
Check: checkGeoShardedOldSchema(clusterName, 2, 1, true, false),
},
},
})
}

func TestMigAdvancedCluster_shardedTransitionFromOldToNewSchema(t *testing.T) {
func TestMigAdvancedCluster_shardedMigrationFromOldToNewSchema(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
Expand All @@ -152,7 +102,7 @@ func TestMigAdvancedCluster_shardedTransitionFromOldToNewSchema(t *testing.T) {
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
ExternalProviders: acc.ExternalProviders("1.17.5"), // last version that did not support new sharding schema or attributes
Config: configShardedTransitionOldToNewSchema(orgID, projectName, clusterName, false),
Check: checkShardedTransitionOldToNewSchema(false),
},
Expand All @@ -165,7 +115,7 @@ func TestMigAdvancedCluster_shardedTransitionFromOldToNewSchema(t *testing.T) {
})
}

func TestMigAdvancedCluster_geoShardedTransitionFromOldToNewSchema(t *testing.T) {
func TestMigAdvancedCluster_geoShardedMigrationFromOldToNewSchema(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
Expand All @@ -177,7 +127,7 @@ func TestMigAdvancedCluster_geoShardedTransitionFromOldToNewSchema(t *testing.T)
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProviders(),
ExternalProviders: acc.ExternalProviders("1.17.5"), // last version that did not support new sharding schema or attributes
Config: configGeoShardedTransitionOldToNewSchema(orgID, projectName, clusterName, false),
Check: checkGeoShardedTransitionOldToNewSchema(false),
},
Expand Down
Loading

0 comments on commit 038ca26

Please sign in to comment.