Skip to content

chore: Fixes some acceptance tests #1970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ func TestAccMigrationBackupRSCloudBackupSnapshot_sharded(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
clusterName = acc.RandomClusterName()
description = "My description in my cluster"
retentionInDays = "4"
config = configSharded(orgID, projectName, description, retentionInDays)
config = configSharded(orgID, projectName, clusterName, description, retentionInDays)
)

resource.ParallelTest(t, resource.TestCase{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func TestAccBackupRSCloudBackupSnapshot_sharded(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
clusterName = acc.RandomClusterName()
description = "My description in my cluster"
retentionInDays = "4"
)
Expand All @@ -81,7 +82,7 @@ func TestAccBackupRSCloudBackupSnapshot_sharded(t *testing.T) {
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
Config: configSharded(orgID, projectName, description, retentionInDays),
Config: configSharded(orgID, projectName, clusterName, description, retentionInDays),
Check: resource.ComposeTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
Expand Down Expand Up @@ -176,7 +177,7 @@ func configBasic(info *acc.ClusterInfo, description, retentionInDays string) str
`, info.ClusterNameStr, info.ProjectIDStr, description, retentionInDays)
}

func configSharded(orgID, projectName, description, retentionInDays string) string {
func configSharded(orgID, projectName, clusterName, description, retentionInDays string) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "backup_project" {
org_id = %[1]q
Expand All @@ -185,7 +186,7 @@ func configSharded(orgID, projectName, description, retentionInDays string) stri

resource "mongodbatlas_advanced_cluster" "my_cluster" {
project_id = mongodbatlas_project.backup_project.id
name = "ClusterSharded"
name = %[3]q
cluster_type = "SHARDED"
backup_enabled = true

Expand All @@ -212,8 +213,8 @@ func configSharded(orgID, projectName, description, retentionInDays string) stri
resource "mongodbatlas_cloud_backup_snapshot" "test" {
project_id = mongodbatlas_advanced_cluster.my_cluster.project_id
cluster_name = mongodbatlas_advanced_cluster.my_cluster.name
description = %[3]q
retention_in_days = %[4]q
description = %[4]q
retention_in_days = %[5]q
}

data "mongodbatlas_cloud_backup_snapshot" "test" {
Expand All @@ -222,5 +223,5 @@ func configSharded(orgID, projectName, description, retentionInDays string) stri
cluster_name = mongodbatlas_advanced_cluster.my_cluster.name
}

`, orgID, projectName, description, retentionInDays)
`, orgID, projectName, clusterName, description, retentionInDays)
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestAccFederatedDatabaseInstanceDS_s3Bucket(t *testing.T) {
projectName = acc.RandomProjectName()
name = acc.RandomName()
policyName = acc.RandomName()
roleName = acc.RandomName()
roleName = acc.RandomIAMRole()
testS3Bucket = os.Getenv("AWS_S3_BUCKET")
region = "VIRGINIA_USA"
federatedInstance = admin.DataLakeTenant{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestAccFederatedDatabaseInstanceDSPlural_basic(t *testing.T) {
firstName = acc.RandomName()
secondName = acc.RandomName()
policyName = acc.RandomName()
roleName = acc.RandomName()
roleName = acc.RandomIAMRole()
testS3Bucket = os.Getenv("AWS_S3_BUCKET")
region = "VIRGINIA_USA"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestAccFederatedDatabaseInstance_s3bucket(t *testing.T) {
projectName = acc.RandomProjectName()
name = acc.RandomName()
policyName = acc.RandomName()
roleName = acc.RandomName()
roleName = acc.RandomIAMRole()
testS3Bucket = os.Getenv("AWS_S3_BUCKET")
region = "VIRGINIA_USA"
)
Expand Down Expand Up @@ -109,6 +109,8 @@ func TestAccFederatedDatabaseInstance_atlasCluster(t *testing.T) {
resourceName = "mongodbatlas_federated_database_instance.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
clusterName1 = acc.RandomClusterName()
clusterName2 = acc.RandomClusterName()
name = acc.RandomName()
)

Expand All @@ -118,7 +120,7 @@ func TestAccFederatedDatabaseInstance_atlasCluster(t *testing.T) {
Steps: []resource.TestStep{
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: configWithCluster(projectName, orgID, name),
Config: configWithCluster(orgID, projectName, clusterName1, clusterName2, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "name", name),
Expand All @@ -131,51 +133,51 @@ func TestAccFederatedDatabaseInstance_atlasCluster(t *testing.T) {
})
}

func configWithCluster(projectName, orgID, name string) string {
func configWithCluster(orgID, projectName, clusterName1, clusterName2, name string) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "project-tf" {
name = %[1]q
org_id = %[2]q
resource "mongodbatlas_project" "project-tf" {
org_id = %[1]q
name = %[2]q
}

resource "mongodbatlas_cluster" "cluster-1" {
project_id = mongodbatlas_project.project-tf.id
provider_name = "AWS"
name = "tfCluster0"
backing_provider_name = "AWS"
provider_region_name = "EU_WEST_2"
provider_instance_size_name = "M10"
project_id = mongodbatlas_project.project-tf.id
provider_name = "AWS"
name = %[3]q
backing_provider_name = "AWS"
provider_region_name = "EU_WEST_2"
provider_instance_size_name = "M10"
}


resource "mongodbatlas_cluster" "cluster-2" {
project_id = mongodbatlas_project.project-tf.id
provider_name = "AWS"
name = "tfCluster1"
backing_provider_name = "AWS"
provider_region_name = "EU_WEST_2"
provider_instance_size_name = "M10"
project_id = mongodbatlas_project.project-tf.id
provider_name = "AWS"
name = %[4]q
backing_provider_name = "AWS"
provider_region_name = "EU_WEST_2"
provider_instance_size_name = "M10"
}

resource "mongodbatlas_federated_database_instance" "test" {
project_id = mongodbatlas_project.project-tf.id
name = %[3]q
storage_databases {
name = "VirtualDatabase0"
collections {
name = "VirtualCollection0"
data_sources {
collection = "listingsAndReviews"
database = "sample_airbnb"
store_name = mongodbatlas_cluster.cluster-1.name
}
data_sources {
project_id = mongodbatlas_project.project-tf.id
name = %[5]q
storage_databases {
name = "VirtualDatabase0"
collections {
name = "VirtualCollection0"
data_sources {
collection = "listingsAndReviews"
database = "sample_airbnb"
store_name = mongodbatlas_cluster.cluster-1.name
}
data_sources {

collection = "listingsAndReviews"
database = "sample_airbnb"
store_name = mongodbatlas_cluster.cluster-2.name
collection = "listingsAndReviews"
database = "sample_airbnb"
store_name = mongodbatlas_cluster.cluster-2.name
}
}
}
}

storage_stores {
Expand Down Expand Up @@ -238,7 +240,7 @@ func configWithCluster(projectName, orgID, name string) string {
}
}
}
`, projectName, orgID, name)
`, orgID, projectName, clusterName1, clusterName2, name)
}

func importStateIDFuncS3Bucket(resourceName, s3Bucket string) resource.ImportStateIdFunc {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import (
)

const (
errorAccessListCreate = "error creating Project IP Access List information: %s"
errorAccessListRead = "error getting Project IP Access List information: %s"
errorAccessListDelete = "error deleting Project IP Access List information: %s"
projectIPAccessListTimeout = 45 * time.Minute
projectIPAccessListTimeoutRead = 2 * time.Minute
projectIPAccessListMinTimeout = 2 * time.Second
projectIPAccessListDelay = 4 * time.Second
projectIPAccessListRetry = 2 * time.Minute
errorAccessListCreate = "error creating Project IP Access List information: %s"
errorAccessListRead = "error getting Project IP Access List information: %s"
errorAccessListDelete = "error deleting Project IP Access List information: %s"
timeoutCreateDelete = 45 * time.Minute
timeoutRead = 2 * time.Minute
timeoutRetryItem = 2 * time.Minute
minTimeoutCreate = 10 * time.Second
delayCreate = 10 * time.Second
)

type TfProjectIPAccessListModel struct {
Expand Down Expand Up @@ -182,9 +182,9 @@ func (r *projectIPAccessListRS) Create(ctx context.Context, req resource.CreateR

return entry, "created", nil
},
Timeout: projectIPAccessListTimeout,
Delay: projectIPAccessListDelay,
MinTimeout: projectIPAccessListMinTimeout,
Timeout: timeoutCreateDelete,
Delay: delayCreate,
MinTimeout: minTimeoutCreate,
}

// Wait, catching any errors
Expand Down Expand Up @@ -220,7 +220,7 @@ func (r *projectIPAccessListRS) Read(ctx context.Context, req resource.ReadReque
return
}

timeout, diags := projectIPAccessListModelState.Timeouts.Read(ctx, projectIPAccessListTimeoutRead)
timeout, diags := projectIPAccessListModelState.Timeouts.Read(ctx, timeoutRead)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
Expand Down Expand Up @@ -274,7 +274,7 @@ func (r *projectIPAccessListRS) Delete(ctx context.Context, req resource.DeleteR
connV2 := r.Client.AtlasV2
projectID := projectIPAccessListModelState.ProjectID.ValueString()

timeout, diags := projectIPAccessListModelState.Timeouts.Delete(ctx, projectIPAccessListTimeout)
timeout, diags := projectIPAccessListModelState.Timeouts.Delete(ctx, timeoutCreateDelete)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
Expand Down Expand Up @@ -335,7 +335,7 @@ func (r *projectIPAccessListRS) ImportState(ctx context.Context, req resource.Im

func isEntryInProjectAccessList(ctx context.Context, connV2 *admin.APIClient, projectID, entry string) (*admin.NetworkPermissionEntry, bool, error) {
var out admin.NetworkPermissionEntry
err := retry.RetryContext(ctx, projectIPAccessListRetry, func() *retry.RetryError {
err := retry.RetryContext(ctx, timeoutRetryItem, func() *retry.RetryError {
accessList, httpResponse, err := connV2.ProjectIPAccessListApi.GetProjectIpList(ctx, projectID, entry).Execute()
if err != nil {
switch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (

func TestAccStreamDSStreamConnection_kafkaPlaintext(t *testing.T) {
var (
dataSourceName = "data.mongodbatlas_stream_connection.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acc.RandomProjectName()
instanceName = acc.RandomName()
dataSourceName = acc.RandomName()
)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBetaFlag(t); acc.PreCheckBasic(t) },
Expand Down
5 changes: 5 additions & 0 deletions internal/testutil/acc/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
prefixName = "test-acc-tf"
prefixProject = prefixName + "-p"
prefixCluster = prefixName + "-c"
prefixIAMRole = "mongodb-atlas-" + prefixName
)

func RandomName() string {
Expand All @@ -24,6 +25,10 @@ func RandomClusterName() string {
return acctest.RandomWithPrefix(prefixCluster)
}

func RandomIAMRole() string {
return acctest.RandomWithPrefix(prefixIAMRole)
}

func RandomIP(a, b, c byte) string {
return fmt.Sprintf("%d.%d.%d.%d", a, b, c, acctest.RandIntRange(0, 255))
}
Expand Down