|
1 | 1 | package onlinearchive_test
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "context" |
5 | 4 | "fmt"
|
6 |
| - "log" |
7 | 5 | "regexp"
|
8 | 6 | "testing"
|
9 |
| - "time" |
10 | 7 |
|
11 | 8 | "github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
12 |
| - "github.com/hashicorp/terraform-plugin-testing/terraform" |
13 | 9 | "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
|
14 | 10 | )
|
15 | 11 |
|
@@ -43,9 +39,7 @@ func TestAccBackupRSOnlineArchive(t *testing.T) {
|
43 | 39 | Steps: []resource.TestStep{
|
44 | 40 | {
|
45 | 41 | Config: clusterTerraformStr,
|
46 |
| - Check: resource.ComposeAggregateTestCheckFunc( |
47 |
| - populateWithSampleData(clusterResourceName, projectID, clusterName), |
48 |
| - ), |
| 42 | + Check: acc.PopulateWithSampleDataTestCheck(projectID, clusterName), |
49 | 43 | },
|
50 | 44 | {
|
51 | 45 | Config: configWithDailySchedule(clusterTerraformStr, clusterResourceName, 1, 7),
|
@@ -141,9 +135,7 @@ func TestAccBackupRSOnlineArchiveBasic(t *testing.T) {
|
141 | 135 | Steps: []resource.TestStep{
|
142 | 136 | {
|
143 | 137 | Config: clusterTerraformStr,
|
144 |
| - Check: resource.ComposeAggregateTestCheckFunc( |
145 |
| - populateWithSampleData(clusterResourceName, projectID, clusterName), |
146 |
| - ), |
| 138 | + Check: acc.PopulateWithSampleDataTestCheck(projectID, clusterName), |
147 | 139 | },
|
148 | 140 | {
|
149 | 141 | Config: configWithoutSchedule(clusterTerraformStr, clusterResourceName),
|
@@ -190,9 +182,7 @@ func TestAccBackupRSOnlineArchiveWithProcessRegion(t *testing.T) {
|
190 | 182 | Steps: []resource.TestStep{
|
191 | 183 | {
|
192 | 184 | Config: clusterTerraformStr,
|
193 |
| - Check: resource.ComposeAggregateTestCheckFunc( |
194 |
| - populateWithSampleData(clusterResourceName, projectID, clusterName), |
195 |
| - ), |
| 185 | + Check: acc.PopulateWithSampleDataTestCheck(projectID, clusterName), |
196 | 186 | },
|
197 | 187 | {
|
198 | 188 | Config: configWithDataProcessRegion(clusterTerraformStr, clusterResourceName, cloudProvider, processRegion),
|
@@ -239,58 +229,6 @@ func TestAccBackupRSOnlineArchiveInvalidProcessRegion(t *testing.T) {
|
239 | 229 | })
|
240 | 230 | }
|
241 | 231 |
|
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 |
| - |
294 | 232 | func configWithDailySchedule(clusterTerraformStr, clusterResourceName string, startHour, deleteExpirationDays int) string {
|
295 | 233 | var dataExpirationRuleBlock string
|
296 | 234 | if deleteExpirationDays > 0 {
|
|
0 commit comments