Skip to content

test: Adds collection restore job acceptance tests - #4671

Merged
EspenAlbert merged 9 commits into
CLOUDP-435981_collection-restore-docsfrom
CLOUDP-435981_collection-restore-acc-tests
Aug 26, 2026
Merged

test: Adds collection restore job acceptance tests#4671
EspenAlbert merged 9 commits into
CLOUDP-435981_collection-restore-docsfrom
CLOUDP-435981_collection-restore-acc-tests

Conversation

@EspenAlbert

@EspenAlbert EspenAlbert commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Description

Adds acceptance tests for mongodbatlas_cloud_backup_collection_restore_job and snapshot database data sources, plus a shared fixture that provisions a backup-enabled source cluster and on-demand snapshot. CI gets a backup_collection_restore test group.

Link to any related issue(s): CLOUDP-435981

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fix and verified my code
  • If changes include deprecations or removals I have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

External reuse is supported via MONGODB_ATLAS_PROJECT_ID, MONGODB_ATLAS_CLUSTER_NAME, and MONGODB_ATLAS_SNAPSHOT_ID. The execution cluster helper can enable cloud backup and PIT when the fixture creates it.

@EspenAlbert EspenAlbert changed the title CLOUDP 435981 collection restore acc tests test: Adds collection restore job acceptance tests Aug 24, 2026
@EspenAlbert
EspenAlbert requested a lite review from Copilot August 24, 2026 07:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a shared acceptance-test fixture and new acceptance tests to validate Atlas Cloud Backup collection restore jobs and snapshot database/collection discovery, and wires them into CI via a dedicated backup_collection_restore test group.

Changes:

  • Introduces a reusable fixture that provisions (or reuses via env vars) a backup/PIT-enabled source cluster plus an on-demand snapshot, along with helper pollers for collection-restore jobs.
  • Adds new acceptance tests for mongodbatlas_cloud_backup_collection_restore_job and snapshot database/collection data sources.
  • Extends the acceptance test runner workflow to include a backup_collection_restore change-detection group and job.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/testutil/acc/shared_resource.go Adds internal helper to create an execution cluster with backup/PIT toggles for fixture-driven tests.
internal/testutil/acc/cloud_backup_collection_restore_fixture.go New shared fixture and helper functions for collection-restore acceptance tests (snapshot creation, job polling, env reuse).
internal/testutil/acc/cloud_backup_collection_restore_fixture_test.go Unit tests for fixture helper functions (env parsing, timestamp conversion, backup/PIT flag checks).
internal/testutil/acc/atlas.go Extends cluster creation helpers to allow enabling cloud backup and PIT for fixture-created clusters.
internal/serviceapi/cloudbackupsnapshotdatabase/main_test.go Adds TestMain to run acceptance harness for the snapshot database acceptance test package.
internal/serviceapi/cloudbackupsnapshotdatabase/data_source_test.go Adds acceptance coverage for snapshot database and database-collections discovery data sources.
internal/serviceapi/cloudbackupcollectionrestorejob/resource_test.go Adds acceptance coverage for collection restore job resource + related data sources (incl. PIT and timeout behaviors).
internal/serviceapi/cloudbackupcollectionrestorejob/main_test.go Adds TestMain to run acceptance harness for the restore job acceptance test package.
.github/workflows/acceptance-tests-runner.yml Adds backup_collection_restore change-detection filter and a dedicated acceptance-test job.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/testutil/acc/cloud_backup_collection_restore_fixture.go
Comment thread internal/testutil/acc/cloud_backup_collection_restore_fixture.go
@EspenAlbert
EspenAlbert force-pushed the CLOUDP-435981_collection-restore-acc-tests branch 2 times, most recently from 0ac624b to b2eff2b Compare August 24, 2026 09:23
@EspenAlbert
EspenAlbert force-pushed the CLOUDP-435981_collection-restore-acc-tests branch 2 times, most recently from 91f4c3d to 355f27d Compare August 24, 2026 09:45
@EspenAlbert
EspenAlbert marked this pull request as ready for review August 24, 2026 09:50
@EspenAlbert
EspenAlbert requested a review from a team as a code owner August 24, 2026 09:50
@EspenAlbert
EspenAlbert requested a lite review from Copilot August 24, 2026 09:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

internal/testutil/acc/cloud_backup_collection_restore_fixture.go:254

  • Same response-body leak pattern as GetCollectionRestoreJob: on HTTP errors UntypedAPICall returns (resp, err) and the body should be closed before returning.
func LatestCollectionRestoreJobID(ctx context.Context, projectID, clusterName, destClusterName string) (string, error) {
	resp, err := MongoDBClient.UntypedAPICall(ctx, collectionRestoreJobCall(projectID, clusterName, ""), nil)
	if err != nil {
		return "", err
	}

Comment thread internal/testutil/acc/cloud_backup_collection_restore_fixture.go
@augmentcode

augmentcode Bot commented Aug 24, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: Adds acceptance coverage for collection-level cloud backup restores and snapshot namespace discovery.

  • Adds same-cluster snapshot restore coverage for database renames and collection restore results.
  • Adds cross-cluster point-in-time restore coverage using database and collection suffixes.
  • Adds an invalid source-collection scenario and a short create-timeout cleanup scenario.
  • Introduces a process-wide fixture for a backup- and PIT-enabled source cluster with sample data.
  • Allows the fixture to reuse a supplied project, cluster, and completed snapshot through environment variables.
  • Adds helpers to discover and wait for collection restore jobs through the versioned Atlas API.
  • Adds snapshot database and collection discovery data-source acceptance coverage.
  • Extends generated advanced-cluster test HCL to support an explicit electable-node disk size.
  • Extends cluster creation helpers to request cloud backup and PIT when needed.
  • Adds a dedicated CI change-detection group and acceptance-test job for this coverage.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread internal/testutil/acc/cloud_backup_collection_restore_fixture.go Outdated
@EspenAlbert
EspenAlbert force-pushed the CLOUDP-435981_collection-restore-acc-tests branch from 355f27d to 6d6acc7 Compare August 25, 2026 14:55
@EspenAlbert
EspenAlbert force-pushed the CLOUDP-435981_collection-restore-acc-tests branch from 6d6acc7 to 312ede6 Compare August 25, 2026 15:07
@EspenAlbert
EspenAlbert force-pushed the CLOUDP-435981_collection-restore-acc-tests branch from 312ede6 to 88b1490 Compare August 25, 2026 16:33
@EspenAlbert
EspenAlbert force-pushed the CLOUDP-435981_collection-restore-acc-tests branch from 88b1490 to 1e2c138 Compare August 25, 2026 16:52
@EspenAlbert
EspenAlbert marked this pull request as draft August 26, 2026 07:42
@EspenAlbert

Copy link
Copy Markdown
Collaborator Author

Need to fix the change in the plural data source

@EspenAlbert
EspenAlbert marked this pull request as ready for review August 26, 2026 09:13
@EspenAlbert

Copy link
Copy Markdown
Collaborator Author

Tests fixed, and all checks passing again:
ok github.com/mongodb/terraform-provider-mongodbatlas/internal/serviceapi/cloudbackupcollectionrestorejob2951.963s

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread internal/testutil/acc/cloud_backup_collection_restore_fixture.go
Comment thread internal/serviceapi/cloudbackupcollectionrestorejob/resource_test.go Outdated
Comment on lines +297 to +304
stateConf := retry.StateChangeConf{
Pending: []string{"INITIALIZING", "IN_PROGRESS", "FINALIZING"},
Target: []string{wantState},
Timeout: constant.DefaultTimeout,
MinTimeout: 1 * time.Minute,
Delay: 30 * time.Second,
Refresh: func() (any, string, error) {
body, err := GetCollectionRestoreJob(ctx, projectID, clusterName, jobID)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: A lot of code here seems associated to triggering and handling a restore job, couldnt we use the TF resource for this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy-path tests already POST through the TF resource. These helpers only GET/poll.

We still need them because:

  • Delete is a no-op (no public cancel API)
  • A timed-out create never records job_id, so Terraform state is empty
  • CheckDestroy has to find that leftover job and wait until dest-cluster teardown reaches CANCELED

@EspenAlbert
EspenAlbert force-pushed the CLOUDP-435981_collection-restore-acc-tests branch from ccd5a37 to 831f6e8 Compare August 26, 2026 09:46
@EspenAlbert
EspenAlbert force-pushed the CLOUDP-435981_collection-restore-acc-tests branch from 831f6e8 to 01c64e2 Compare August 26, 2026 12:21
@EspenAlbert
EspenAlbert force-pushed the CLOUDP-435981_collection-restore-acc-tests branch from 01c64e2 to 844ba17 Compare August 26, 2026 12:28
@EspenAlbert
EspenAlbert force-pushed the CLOUDP-435981_collection-restore-acc-tests branch from 844ba17 to 5e61eed Compare August 26, 2026 12:57
@EspenAlbert
EspenAlbert force-pushed the CLOUDP-435981_collection-restore-acc-tests branch from 913f764 to 3689827 Compare August 26, 2026 13:39

@AgustinBettati AgustinBettati left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

cfg.databaseTarget = renamedDB
cfg.collectionSource = restaurantsNS
cfg.withDataSources = true
filtered := cfg.withCollectionsFilter(restaurantsNS)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Comment thread internal/testutil/acc/cloud_backup_collection_restore_fixture_test.go Outdated
@EspenAlbert
EspenAlbert merged commit 78dbacb into master Aug 26, 2026
53 checks passed
@EspenAlbert
EspenAlbert deleted the CLOUDP-435981_collection-restore-acc-tests branch August 26, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants