Skip to content

Commit 96b3a06

Browse files
authored
chore: Fixes search index tests using an existing collection (#2985)
* make PopulateWithSampleData public * fix tests * simplify retry * delete project cluster created in existing project execution * doc * param to populate data in execution cluster * fix retry * remove guide * remove changelog * refactor retry logic * remove databaseAndCollection
1 parent 14ac55f commit 96b3a06

File tree

12 files changed

+143
-181
lines changed

12 files changed

+143
-181
lines changed

internal/common/retrystrategy/retry_state.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ const (
44
RetryStrategyActiveState = "ACTIVE"
55
RetryStrategyCompletedState = "COMPLETED"
66
RetryStrategyCreatingState = "CREATING"
7+
RetryStrategyDeleteRequestedState = "DELETE_REQUESTED"
78
RetryStrategyDeletedState = "DELETED"
89
RetryStrategyDeletingState = "DELETING"
10+
RetryStrategyDoneState = "DONE"
911
RetryStrategyErrorState = "ERROR"
1012
RetryStrategyFailedState = "FAILED"
1113
RetryStrategyIdleState = "IDLE"
1214
RetryStrategyInitiatingState = "INITIATING"
1315
RetryStrategyPausedState = "PAUSED"
16+
RetryStrategyPendingState = "PENDING"
1417
RetryStrategyPendingAcceptanceState = "PENDING_ACCEPTANCE"
1518
RetryStrategyPendingRecreationState = "PENDING_RECREATION"
16-
RetryStrategyPendingState = "PENDING"
1719
RetryStrategyRepairingState = "REPAIRING"
1820
RetryStrategyRepeatingState = "REPEATING"
1921
RetryStrategyUpdatingState = "UPDATING"
20-
RetryStrategyDeleteRequestedState = "DELETE_REQUESTED"
21-
RetryStrategyDoneState = "DONE"
2222
RetryStrategyWorkingState = "WORKING"
2323
)

internal/service/ldapverify/resource_ldap_verify_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestAccLDAPVerify_withConfiguration_CACertificate(t *testing.T) {
2929
password = os.Getenv("MONGODB_ATLAS_LDAP_PASSWORD")
3030
port = os.Getenv("MONGODB_ATLAS_LDAP_PORT")
3131
caCertificate = os.Getenv("MONGODB_ATLAS_LDAP_CA_CERTIFICATE")
32-
projectID, _ = acc.ClusterNameExecution(t)
32+
projectID, _ = acc.ClusterNameExecution(t, false)
3333
)
3434

3535
resource.Test(t, resource.TestCase{
@@ -65,7 +65,7 @@ func basicTestCase(tb testing.TB) *resource.TestCase {
6565
username = os.Getenv("MONGODB_ATLAS_LDAP_USERNAME")
6666
password = os.Getenv("MONGODB_ATLAS_LDAP_PASSWORD")
6767
port = os.Getenv("MONGODB_ATLAS_LDAP_PORT")
68-
projectID, _ = acc.ClusterNameExecution(tb) // cluster needed to avoid error: No clusters available to perform LDAP connectivity verification
68+
projectID, _ = acc.ClusterNameExecution(tb, false) // cluster needed to avoid error: No clusters available to perform LDAP connectivity verification
6969
)
7070

7171
return &resource.TestCase{

internal/service/mongodbemployeeaccessgrant/resource_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestAccMongoDBEmployeeAccessGrant_basic(t *testing.T) {
2828

2929
func basicTestCase(tb testing.TB) *resource.TestCase {
3030
tb.Helper()
31-
projectID, clusterName := acc.ClusterNameExecution(tb)
31+
projectID, clusterName := acc.ClusterNameExecution(tb, false)
3232
return &resource.TestCase{
3333
PreCheck: func() { acc.PreCheckBasic(tb) },
3434
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
@@ -63,7 +63,7 @@ func basicTestCase(tb testing.TB) *resource.TestCase {
6363
}
6464

6565
func TestAccMongoDBEmployeeAccessGrant_invalidExpirationTime(t *testing.T) {
66-
projectID, clusterName := acc.ClusterNameExecution(t)
66+
projectID, clusterName := acc.ClusterNameExecution(t, false)
6767
resource.Test(t, resource.TestCase{
6868
PreCheck: func() { acc.PreCheckBasic(t) },
6969
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
@@ -78,7 +78,7 @@ func TestAccMongoDBEmployeeAccessGrant_invalidExpirationTime(t *testing.T) {
7878
}
7979

8080
func TestAccMongoDBEmployeeAccessGrant_invalidExpirationTimeUpdate(t *testing.T) {
81-
projectID, clusterName := acc.ClusterNameExecution(t)
81+
projectID, clusterName := acc.ClusterNameExecution(t, false)
8282
resource.Test(t, resource.TestCase{
8383
PreCheck: func() { acc.PreCheckBasic(t) },
8484
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
@@ -97,7 +97,7 @@ func TestAccMongoDBEmployeeAccessGrant_invalidExpirationTimeUpdate(t *testing.T)
9797
}
9898

9999
func TestAccMongoDBEmployeeAccessGrant_invalidGrantType(t *testing.T) {
100-
projectID, clusterName := acc.ClusterNameExecution(t)
100+
projectID, clusterName := acc.ClusterNameExecution(t, false)
101101
resource.Test(t, resource.TestCase{
102102
PreCheck: func() { acc.PreCheckBasic(t) },
103103
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
@@ -112,7 +112,7 @@ func TestAccMongoDBEmployeeAccessGrant_invalidGrantType(t *testing.T) {
112112
}
113113

114114
func TestAccMongoDBEmployeeAccessGrant_invalidGrantTypeUpdate(t *testing.T) {
115-
projectID, clusterName := acc.ClusterNameExecution(t)
115+
projectID, clusterName := acc.ClusterNameExecution(t, false)
116116
resource.Test(t, resource.TestCase{
117117
PreCheck: func() { acc.PreCheckBasic(t) },
118118
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,

internal/service/onlinearchive/resource_online_archive_migration_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ func TestMigBackupRSOnlineArchiveWithNoChangeBetweenVersions(t *testing.T) {
3131
{
3232
ExternalProviders: mig.ExternalProviders(),
3333
Config: clusterTerraformStr,
34-
Check: resource.ComposeAggregateTestCheckFunc(
35-
populateWithSampleData(clusterResourceName, projectID, clusterName),
36-
),
34+
Check: acc.PopulateWithSampleDataTestCheck(projectID, clusterName),
3735
},
3836
{
3937
ExternalProviders: mig.ExternalProviders(),

internal/service/onlinearchive/resource_online_archive_test.go

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package onlinearchive_test
22

33
import (
4-
"context"
54
"fmt"
6-
"log"
75
"regexp"
86
"testing"
9-
"time"
107

118
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
12-
"github.com/hashicorp/terraform-plugin-testing/terraform"
139
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
1410
)
1511

@@ -43,9 +39,7 @@ func TestAccBackupRSOnlineArchive(t *testing.T) {
4339
Steps: []resource.TestStep{
4440
{
4541
Config: clusterTerraformStr,
46-
Check: resource.ComposeAggregateTestCheckFunc(
47-
populateWithSampleData(clusterResourceName, projectID, clusterName),
48-
),
42+
Check: acc.PopulateWithSampleDataTestCheck(projectID, clusterName),
4943
},
5044
{
5145
Config: configWithDailySchedule(clusterTerraformStr, clusterResourceName, 1, 7),
@@ -141,9 +135,7 @@ func TestAccBackupRSOnlineArchiveBasic(t *testing.T) {
141135
Steps: []resource.TestStep{
142136
{
143137
Config: clusterTerraformStr,
144-
Check: resource.ComposeAggregateTestCheckFunc(
145-
populateWithSampleData(clusterResourceName, projectID, clusterName),
146-
),
138+
Check: acc.PopulateWithSampleDataTestCheck(projectID, clusterName),
147139
},
148140
{
149141
Config: configWithoutSchedule(clusterTerraformStr, clusterResourceName),
@@ -190,9 +182,7 @@ func TestAccBackupRSOnlineArchiveWithProcessRegion(t *testing.T) {
190182
Steps: []resource.TestStep{
191183
{
192184
Config: clusterTerraformStr,
193-
Check: resource.ComposeAggregateTestCheckFunc(
194-
populateWithSampleData(clusterResourceName, projectID, clusterName),
195-
),
185+
Check: acc.PopulateWithSampleDataTestCheck(projectID, clusterName),
196186
},
197187
{
198188
Config: configWithDataProcessRegion(clusterTerraformStr, clusterResourceName, cloudProvider, processRegion),
@@ -239,58 +229,6 @@ func TestAccBackupRSOnlineArchiveInvalidProcessRegion(t *testing.T) {
239229
})
240230
}
241231

242-
// populateWithSampleData adds Sample Data to the cluster otherwise online archive won't work
243-
func populateWithSampleData(resourceName, projectID, clusterName string) resource.TestCheckFunc {
244-
return func(s *terraform.State) error {
245-
rs, ok := s.RootModule().Resources[resourceName]
246-
if !ok {
247-
return fmt.Errorf("not found: %s", resourceName)
248-
}
249-
if rs.Primary.ID == "" {
250-
return fmt.Errorf("no ID is set")
251-
}
252-
conn := acc.ConnV2()
253-
ctx := context.Background()
254-
_, _, err := conn.ClustersApi.GetCluster(ctx, projectID, clusterName).Execute()
255-
if err != nil {
256-
return fmt.Errorf("cluster(%s:%s) does not exist %s", projectID, clusterName, err)
257-
}
258-
job, _, err := conn.ClustersApi.LoadSampleDataset(context.Background(), projectID, clusterName).Execute()
259-
if err != nil {
260-
return fmt.Errorf("cluster(%s:%s) loading sample data set error %s", projectID, clusterName, err)
261-
}
262-
if job == nil {
263-
return fmt.Errorf("cluster(%s:%s) loading sample data set error, no job found", projectID, clusterName)
264-
}
265-
ticker := time.NewTicker(30 * time.Second)
266-
267-
JOB:
268-
for {
269-
select {
270-
case <-time.After(20 * time.Second):
271-
log.Println("timeout elapsed ....")
272-
case <-ticker.C:
273-
job, _, err = conn.ClustersApi.GetSampleDatasetLoadStatus(ctx, projectID, job.GetId()).Execute()
274-
fmt.Println("querying for job ")
275-
if err != nil {
276-
return fmt.Errorf("cluster(%s:%s) failed to query for job, %s", projectID, clusterName, err)
277-
}
278-
if job == nil {
279-
return fmt.Errorf("cluster(%s:%s) failed to query for job, no job found", projectID, clusterName)
280-
}
281-
if job.GetState() != "WORKING" {
282-
break JOB
283-
}
284-
}
285-
}
286-
287-
if job.GetState() != "COMPLETED" {
288-
return fmt.Errorf("cluster(%s:%s) working sample data set error %s", projectID, job.GetId(), job.GetState())
289-
}
290-
return nil
291-
}
292-
}
293-
294232
func configWithDailySchedule(clusterTerraformStr, clusterResourceName string, startHour, deleteExpirationDays int) string {
295233
var dataExpirationRuleBlock string
296234
if deleteExpirationDays > 0 {

0 commit comments

Comments
 (0)