diff --git a/internal/cli/atlas/clusters/create_test.go b/internal/cli/atlas/clusters/create_test.go index 66b8349cdf..00604f3739 100644 --- a/internal/cli/atlas/clusters/create_test.go +++ b/internal/cli/atlas/clusters/create_test.go @@ -46,7 +46,7 @@ func TestCreateOpts_Run(t *testing.T) { members: 3, diskSizeGB: 10, backup: false, - mdbVersion: "4.4", + mdbVersion: "7.0", store: mockStore, } diff --git a/internal/cli/atlas/clusters/update_test.go b/internal/cli/atlas/clusters/update_test.go index 6c61e1ce25..2d0ccd2f38 100644 --- a/internal/cli/atlas/clusters/update_test.go +++ b/internal/cli/atlas/clusters/update_test.go @@ -41,7 +41,7 @@ func TestUpdate_Run(t *testing.T) { name: "ProjectBar", tier: atlasM2, diskSizeGB: 10, - mdbVersion: "4.4", + mdbVersion: "7.0", store: mockStore, } diff --git a/test/e2e/atlas/atlas_e2e_test_generator_test.go b/test/e2e/atlas/atlas_e2e_test_generator_test.go index 23e14e2e88..aaf8597d45 100644 --- a/test/e2e/atlas/atlas_e2e_test_generator_test.go +++ b/test/e2e/atlas/atlas_e2e_test_generator_test.go @@ -335,7 +335,10 @@ func (g *atlasE2ETestGenerator) generateCluster() { } if g.mDBVer == "" { - g.mDBVer = e2eMDBVer + mdbVersion, e := MongoDBMajorVersion() + require.NoError(g.t, e) + + g.mDBVer = mdbVersion } g.clusterName, g.clusterRegion, err = deployClusterForProject(g.projectID, g.tier, g.mDBVer, g.enableBackup) diff --git a/test/e2e/atlas/backup_export_jobs_test.go b/test/e2e/atlas/backup_export_jobs_test.go index 33c3c4e0b6..77fecb9084 100644 --- a/test/e2e/atlas/backup_export_jobs_test.go +++ b/test/e2e/atlas/backup_export_jobs_test.go @@ -38,6 +38,9 @@ func TestExportJobs(t *testing.T) { fmt.Println(clusterName) r.NoError(err) + mdbVersion, err := MongoDBMajorVersion() + r.NoError(err) + const cloudProvider = "AWS" iamRoleID := os.Getenv("E2E_CLOUD_ROLE_ID") bucketName := os.Getenv("E2E_TEST_BUCKET") @@ -56,7 +59,7 @@ func TestExportJobs(t *testing.T) { "--tier", tierM10, "--region=US_EAST_1", "--provider", e2eClusterProvider, - "--mdbVersion", e2eSharedMDBVer, + "--mdbVersion", mdbVersion, "-o=json") cmd.Env = os.Environ() resp, err := cmd.CombinedOutput() @@ -64,7 +67,7 @@ func TestExportJobs(t *testing.T) { var cluster *atlasv2.AdvancedClusterDescription r.NoError(json.Unmarshal(resp, &cluster)) - ensureCluster(t, cluster, clusterName, e2eSharedMDBVer, 10, false) + ensureCluster(t, cluster, clusterName, mdbVersion, 10, false) }) t.Cleanup(func() { require.NoError(t, deleteClusterForProject("", clusterName)) diff --git a/test/e2e/atlas/backup_snapshot_test.go b/test/e2e/atlas/backup_snapshot_test.go index a2ddff804f..ddbcc48c40 100644 --- a/test/e2e/atlas/backup_snapshot_test.go +++ b/test/e2e/atlas/backup_snapshot_test.go @@ -35,6 +35,9 @@ func TestSnapshots(t *testing.T) { clusterName, err := RandClusterName() r.NoError(err) + mdbVersion, err := MongoDBMajorVersion() + r.NoError(err) + var snapshotID string t.Run("Create cluster", func(t *testing.T) { @@ -46,7 +49,7 @@ func TestSnapshots(t *testing.T) { "--tier", tierM10, "--region=US_EAST_1", "--provider", e2eClusterProvider, - "--mdbVersion", e2eSharedMDBVer, + "--mdbVersion", mdbVersion, "-o=json") cmd.Env = os.Environ() resp, err := cmd.CombinedOutput() @@ -54,7 +57,7 @@ func TestSnapshots(t *testing.T) { var cluster *atlasv2.AdvancedClusterDescription require.NoError(t, json.Unmarshal(resp, &cluster)) - ensureCluster(t, cluster, clusterName, e2eSharedMDBVer, 10, false) + ensureCluster(t, cluster, clusterName, mdbVersion, 10, false) }) t.Cleanup(func() { require.NoError(t, deleteClusterForProject("", clusterName)) diff --git a/test/e2e/atlas/clusters_file_test.go b/test/e2e/atlas/clusters_file_test.go index 07325dc202..2b2c6cc27d 100644 --- a/test/e2e/atlas/clusters_file_test.go +++ b/test/e2e/atlas/clusters_file_test.go @@ -16,11 +16,13 @@ package atlas_test import ( + "bytes" "encoding/json" "fmt" "os" "os/exec" "testing" + "text/template" "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config" "github.com/mongodb/mongodb-atlas-cli/atlascli/test/e2e" @@ -40,10 +42,15 @@ func TestClustersFile(t *testing.T) { clusterFileName, err := RandClusterName() req.NoError(err) - clusterFile := "create_cluster_test.json" - if service := os.Getenv("MCLI_SERVICE"); service == config.CloudGovService { - clusterFile = "create_cluster_gov_test.json" - } + mdbVersion, err := MongoDBMajorVersion() + req.NoError(err) + + clusterFile, err := generateClusterFile(mdbVersion) + req.NoError(err) + + t.Cleanup(func() { + os.Remove(clusterFile) + }) t.Run("Create via file", func(t *testing.T) { cmd := exec.Command(cliPath, @@ -60,7 +67,7 @@ func TestClustersFile(t *testing.T) { var cluster atlasv2.AdvancedClusterDescription req.NoError(json.Unmarshal(resp, &cluster)) - ensureCluster(t, &cluster, clusterFileName, e2eMDBVer, 30, false) + ensureCluster(t, &cluster, clusterFileName, mdbVersion, 30, false) }) t.Run("Watch", func(t *testing.T) { @@ -92,7 +99,7 @@ func TestClustersFile(t *testing.T) { var cluster atlasv2.AdvancedClusterDescription req.NoError(json.Unmarshal(resp, &cluster)) t.Logf("%v\n", cluster) - ensureCluster(t, &cluster, clusterFileName, e2eMDBVer, 40, false) + ensureCluster(t, &cluster, clusterFileName, mdbVersion, 40, false) assert.Empty(t, cluster.GetTags()) }) @@ -126,3 +133,36 @@ func TestClustersFile(t *testing.T) { t.Log(string(resp)) }) } + +func generateClusterFile(mdbVersion string) (string, error) { + data := struct { + MongoDBMajorVersion string + }{ + MongoDBMajorVersion: mdbVersion, + } + + templateFile := "create_cluster_test.json" + if service := os.Getenv("MCLI_SERVICE"); service == config.CloudGovService { + templateFile = "create_cluster_gov_test.json" + } + + tmpl, err := template.ParseFiles(templateFile) + if err != nil { + return "", err + } + + var tempBuffer bytes.Buffer + if err = tmpl.Execute(&tempBuffer, data); err != nil { + return "", err + } + + const clusterFile = "create_cluster.json" + file, err := os.Create(clusterFile) + if err != nil { + return "", err + } + defer file.Close() + + _, err = tempBuffer.WriteTo(file) + return clusterFile, err +} diff --git a/test/e2e/atlas/clusters_flags_test.go b/test/e2e/atlas/clusters_flags_test.go index 453505ec81..c4b9ef2ba4 100644 --- a/test/e2e/atlas/clusters_flags_test.go +++ b/test/e2e/atlas/clusters_flags_test.go @@ -17,10 +17,12 @@ package atlas_test import ( "encoding/json" + "fmt" "os" "os/exec" "testing" + "github.com/Masterminds/semver/v3" "github.com/mongodb/mongodb-atlas-cli/atlascli/test/e2e" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -44,6 +46,12 @@ func TestClustersFlags(t *testing.T) { region, err := g.newAvailableRegion(tier, e2eClusterProvider) req.NoError(err) + mdbVersion, err := MongoDBMajorVersion() + req.NoError(err) + + previousMdbVersion, err := getPreviousMajorVersion(mdbVersion) + req.NoError(err) + t.Run("Create", func(t *testing.T) { cmd := exec.Command(cliPath, clustersEntity, @@ -53,7 +61,7 @@ func TestClustersFlags(t *testing.T) { "--members=3", "--tier", tier, "--provider", e2eClusterProvider, - "--mdbVersion", e2eMDBVer, + "--mdbVersion", previousMdbVersion, "--diskSizeGB", diskSizeGB30, "--enableTerminationProtection", "--projectId", g.projectID, @@ -66,7 +74,7 @@ func TestClustersFlags(t *testing.T) { var cluster *atlasv2.AdvancedClusterDescription require.NoError(t, json.Unmarshal(resp, &cluster)) - ensureCluster(t, cluster, clusterName, e2eMDBVer, 30, true) + ensureCluster(t, cluster, clusterName, previousMdbVersion, 30, true) }) t.Run("Load Sample Data", func(t *testing.T) { @@ -207,7 +215,7 @@ func TestClustersFlags(t *testing.T) { "update", clusterName, "--diskSizeGB", diskSizeGB40, - "--mdbVersion=5.0", + "--mdbVersion", mdbVersion, "--disableTerminationProtection", "--projectId", g.projectID, "-o=json") @@ -218,7 +226,7 @@ func TestClustersFlags(t *testing.T) { var cluster atlasv2.AdvancedClusterDescription require.NoError(t, json.Unmarshal(resp, &cluster)) - ensureCluster(t, &cluster, clusterName, "5.0", 40, false) + ensureCluster(t, &cluster, clusterName, mdbVersion, 40, false) }) t.Run("Delete", func(t *testing.T) { @@ -231,3 +239,12 @@ func TestClustersFlags(t *testing.T) { assert.Contains(t, string(resp), expected) }) } + +func getPreviousMajorVersion(version string) (string, error) { + v, err := semver.NewVersion(version) + if err != nil { + return "", err + } + + return fmt.Sprintf("%d.%d", v.Major()-1, v.Minor()), nil +} diff --git a/test/e2e/atlas/clusters_sharded_test.go b/test/e2e/atlas/clusters_sharded_test.go index a1ee0f9722..f64b7916a2 100644 --- a/test/e2e/atlas/clusters_sharded_test.go +++ b/test/e2e/atlas/clusters_sharded_test.go @@ -43,6 +43,9 @@ func TestShardedCluster(t *testing.T) { region, err := g.newAvailableRegion(tier, e2eClusterProvider) req.NoError(err) + mdbVersion, err := MongoDBMajorVersion() + req.NoError(err) + t.Run("Create sharded cluster", func(t *testing.T) { cmd := exec.Command(cliPath, clustersEntity, @@ -54,7 +57,7 @@ func TestShardedCluster(t *testing.T) { "--members=3", "--tier", tier, "--provider", e2eClusterProvider, - "--mdbVersion", e2eMDBVer, + "--mdbVersion", mdbVersion, "--diskSizeGB", diskSizeGB30, "--projectId", g.projectID, "-o=json") @@ -66,7 +69,7 @@ func TestShardedCluster(t *testing.T) { var cluster atlasv2.AdvancedClusterDescription req.NoError(json.Unmarshal(resp, &cluster)) - ensureCluster(t, &cluster, shardedClusterName, e2eMDBVer, 30, false) + ensureCluster(t, &cluster, shardedClusterName, mdbVersion, 30, false) }) t.Run("Delete sharded cluster", func(t *testing.T) { diff --git a/test/e2e/atlas/create_cluster_gov_test.json b/test/e2e/atlas/create_cluster_gov_test.json index 555d2df4aa..9413c76ea1 100644 --- a/test/e2e/atlas/create_cluster_gov_test.json +++ b/test/e2e/atlas/create_cluster_gov_test.json @@ -9,7 +9,7 @@ "diskSizeGB": 30, "encryptionAtRestProvider": "NONE", "groupId": "60e40e9e9e80a53e4f41686e", - "mongoDBMajorVersion": "4.4", + "mongoDBMajorVersion": "{{.MongoDBMajorVersion}}", "name": "Cluster0", "paused": false, "pitEnabled": true, diff --git a/test/e2e/atlas/create_cluster_test.json b/test/e2e/atlas/create_cluster_test.json index 91b845fbf3..951dfe7550 100644 --- a/test/e2e/atlas/create_cluster_test.json +++ b/test/e2e/atlas/create_cluster_test.json @@ -2,7 +2,7 @@ "backupEnabled":false, "diskSizeGB":30, "numShards":1, - "mongoDBMajorVersion":"4.4", + "mongoDBMajorVersion":"{{.MongoDBMajorVersion}}", "providerSettings":{ "providerName":"GCP", "instanceSizeName":"M10" diff --git a/test/e2e/atlas/helper_test.go b/test/e2e/atlas/helper_test.go index 273d3b2679..df945189b0 100644 --- a/test/e2e/atlas/helper_test.go +++ b/test/e2e/atlas/helper_test.go @@ -130,8 +130,6 @@ const ( e2eGovClusterTier = "M20" e2eSharedClusterTier = "M2" e2eClusterProvider = "AWS" // e2eClusterProvider preferred provider for e2e testing. - e2eMDBVer = "4.4" - e2eSharedMDBVer = "6.0" ) // Backup compliance policy constants.