Skip to content

Commit

Permalink
INTMDB-194: Added func to get db major version for testing (#427)
Browse files Browse the repository at this point in the history
* test: added func to get db majorversion and use it to pass to config via parameter

* test: deleted ebs volume config for testing

Co-authored-by: Edgar López <[email protected]>
  • Loading branch information
coderGo93 and Edgar López authored Apr 6, 2021
1 parent d3a25a5 commit 0bb6c63
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions mongodbatlas/resource_mongodbatlas_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"net/http"
"os"
"testing"

Expand Down Expand Up @@ -843,13 +844,15 @@ func TestAccResourceMongoDBAtlasCluster_tenant(t *testing.T) {
name = fmt.Sprintf("test-acc-%s", acctest.RandString(10))
)

dbMajorVersion := testAccGetMongoDBAtlasMajorVersion()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMongoDBAtlasClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccMongoDBAtlasClusterConfigTenant(projectID, name, "M2", "2"),
Config: testAccMongoDBAtlasClusterConfigTenant(projectID, name, "M2", "2", dbMajorVersion),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster),
testAccCheckMongoDBAtlasClusterAttributes(&cluster, name),
Expand Down Expand Up @@ -879,14 +882,15 @@ func TestAccResourceMongoDBAtlasCluster_tenant_m5(t *testing.T) {
resourceName := "mongodbatlas_cluster.tenant"
projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID")
name := fmt.Sprintf("test-acc-%s", acctest.RandString(10))
dbMajorVersion := testAccGetMongoDBAtlasMajorVersion()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMongoDBAtlasClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccMongoDBAtlasClusterConfigTenant(projectID, name, "M5", "5"),
Config: testAccMongoDBAtlasClusterConfigTenant(projectID, name, "M5", "5", dbMajorVersion),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster),
testAccCheckMongoDBAtlasClusterAttributes(&cluster, name),
Expand All @@ -911,6 +915,13 @@ func testAccCheckMongoDBAtlasClusterImportStateIDFunc(resourceName string) resou
}
}

func testAccGetMongoDBAtlasMajorVersion() string {
conn, _ := matlas.New(http.DefaultClient, matlas.SetBaseURL(matlas.CloudURL))
majorVersion, _, _ := conn.DefaultMongoDBMajorVersion.Get(context.Background())

return majorVersion
}

func testAccCheckMongoDBAtlasClusterExists(resourceName string, cluster *matlas.Cluster) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*matlas.Client)
Expand Down Expand Up @@ -982,7 +993,6 @@ func testAccMongoDBAtlasClusterConfigAWS(projectID, name string, backupEnabled,
// Provider Settings "block"
provider_name = "AWS"
provider_disk_iops = 300
provider_encrypt_ebs_volume = false
provider_instance_size_name = "M30"
provider_region_name = "EU_CENTRAL_1"
}
Expand Down Expand Up @@ -1216,7 +1226,7 @@ func testAccMongoDBAtlasClusterConfigGlobal(projectID, name, backupEnabled strin
`, projectID, name, backupEnabled)
}

func testAccMongoDBAtlasClusterConfigTenant(projectID, name, instanceSize, diskSize string) string {
func testAccMongoDBAtlasClusterConfigTenant(projectID, name, instanceSize, diskSize, majorDBVersion string) string {
return fmt.Sprintf(`
resource "mongodbatlas_cluster" "tenant" {
project_id = "%s"
Expand All @@ -1230,10 +1240,10 @@ func testAccMongoDBAtlasClusterConfigTenant(projectID, name, instanceSize, diskS
provider_instance_size_name = "%s"
//These must be the following values
mongo_db_major_version = "4.2"
mongo_db_major_version = "%s"
auto_scaling_disk_gb_enabled = false
}
`, projectID, name, diskSize, instanceSize)
`, projectID, name, diskSize, instanceSize, majorDBVersion)
}

func testAccMongoDBAtlasClusterConfigTenantUpdated(projectID, name string) string {
Expand Down

0 comments on commit 0bb6c63

Please sign in to comment.