Skip to content

TOOLS-4263 Convert mongorestore namespace mapping tests to Go - #1093

Draft
autarch wants to merge 1 commit into
08-06-tools-4263_convert_mongorestore_bulk_sizing_tests_to_gofrom
08-06-tools-4263_convert_mongorestore_namespace_mapping_tests_to_go
Draft

TOOLS-4263 Convert mongorestore namespace mapping tests to Go#1093
autarch wants to merge 1 commit into
08-06-tools-4263_convert_mongorestore_bulk_sizing_tests_to_gofrom
08-06-tools-4263_convert_mongorestore_namespace_mapping_tests_to_go

Conversation

@autarch

@autarch autarch commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Adds integration/dumprestore/namespace_test.go: six DumpRestoreSuite methods, fourteen cases in total, covering how mongorestore targets and rewrites namespaces. Every fixture document's _id records the namespace it was inserted into, because the JS tests mostly asserted document counts and a count cannot tell a correct restore apart from one that swapped two same-named collections between databases. Every restore also asserts an exact insert count, since mongorestore returns a nil error for a restore that found nothing to do.

JS -> Go mapping (all Go tests live in integration/dumprestore/namespace_test.go):

  • test/qa-tests/jstests/restore/different_collection.js -> TestRestoreIntoDifferentCollection (integration/dumprestore/namespace_test.go) - a single collection's bson file is restored through --db and --collection into a different collection in the same database, into the same collection name in a different database, and into a different collection in a different database, with the documents landing only in the requested target each time.
  • test/qa-tests/jstests/restore/different_db.js -> TestRestoreIntoDifferentDB (integration/dumprestore/namespace_test.go) - a whole database directory is redirected with --db, and then the same dump is remapped with --nsFrom '$db$.$collection$' --nsTo 'otherdest.$db$_$collection$' so that both halves of the namespace are rewritten and the source database name ends up folded into the destination collection names.
  • test/qa-tests/jstests/restore/namespaces.js -> TestRestoreNamespaceMappings (integration/dumprestore/namespace_test.go) - a three-database fixture is restored through a mapping that flattens every source database into one destination, combined in turn with --nsExclude, --nsInclude, and --excludeCollectionsWithPrefix, and then restored again with two --nsFrom/--nsTo pairs that exchange a pair of databases. The swap case is the interesting one: mongorestore resolves every mapping against the original namespace and returns on the first match rather than chaining them, so applying the two pairs in sequence would send everything to one database, and the encoded _ids catch that. Each restored collection is also checked to have kept the index built over a field named for its source namespace, asserting the index key rather than just its name.
  • test/qa-tests/jstests/restore/multiple_dbs.js -> TestRestoreMultipleDBs (integration/dumprestore/namespace_test.go) - two databases that share a collection name round-trip together and each ends up with exactly its own documents.
  • test/qa-tests/jstests/restore/partial_restore.js -> TestPartialRestore (integration/dumprestore/namespace_test.go) - from a dump spanning two databases, restoring one database and then one collection leaves every namespace that was not asked for absent rather than merely empty.
  • test/legacy42/jstests/tool/dumprestore4.js -> TestRestoreIntoDifferentDBBuildsIndexes (integration/dumprestore/namespace_test.go) - covers SERVER-2186: restoring a dump into a differently named database gives the destination the source's indexes, while a same-named database that happens to exist alongside it is left untouched.

One implementation note worth recording: mongodump accepts a single --db and has no --nsInclude, so a dump spanning several databases has to be assembled one database at a time into a shared root, which withMultiDBDump does. Dumping everything instead would sweep admin and config into the dump and then into the restores.

autarch commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

autarch commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

evergreen retry

@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_namespace_mapping_tests_to_go branch from 85f592d to 5ed60e7 Compare August 7, 2026 18:41
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_bulk_sizing_tests_to_go branch from 7e7a9c9 to 8fd09dd Compare August 7, 2026 18:42
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_bulk_sizing_tests_to_go branch from 8fd09dd to fd416b5 Compare August 7, 2026 18:57
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_namespace_mapping_tests_to_go branch 2 times, most recently from 3ca21f8 to b77f71d Compare August 10, 2026 20:44
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_bulk_sizing_tests_to_go branch from fd416b5 to a19b7e3 Compare August 10, 2026 20:44
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_namespace_mapping_tests_to_go branch from b77f71d to b6ef562 Compare August 11, 2026 16:19
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_bulk_sizing_tests_to_go branch 2 times, most recently from 8158853 to e4aa6bb Compare August 11, 2026 17:11
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_namespace_mapping_tests_to_go branch from b6ef562 to e24c7be Compare August 11, 2026 17:11
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_bulk_sizing_tests_to_go branch from e4aa6bb to bd5eab2 Compare August 12, 2026 18:43
Adds `integration/dumprestore/namespace_test.go`: six `DumpRestoreSuite` methods, fourteen cases in total, covering how mongorestore targets and rewrites namespaces. Every fixture document's `_id` records the namespace it was inserted into, because the JS tests mostly asserted document counts and a count cannot tell a correct restore apart from one that swapped two same-named collections between databases. Every restore also asserts an exact insert count, since mongorestore returns a nil error for a restore that found nothing to do.

JS -> Go mapping (all Go tests live in `integration/dumprestore/namespace_test.go`):

- `test/qa-tests/jstests/restore/different_collection.js` -> `TestRestoreIntoDifferentCollection` (`integration/dumprestore/namespace_test.go`) - a single collection's bson file is restored through `--db` and `--collection` into a different collection in the same database, into the same collection name in a different database, and into a different collection in a different database, with the documents landing only in the requested target each time.
- `test/qa-tests/jstests/restore/different_db.js` -> `TestRestoreIntoDifferentDB` (`integration/dumprestore/namespace_test.go`) - a whole database directory is redirected with `--db`, and then the same dump is remapped with `--nsFrom '$db$.$collection$' --nsTo 'otherdest.$db$_$collection$'` so that both halves of the namespace are rewritten and the source database name ends up folded into the destination collection names.
- `test/qa-tests/jstests/restore/namespaces.js` -> `TestRestoreNamespaceMappings` (`integration/dumprestore/namespace_test.go`) - a three-database fixture is restored through a mapping that flattens every source database into one destination, combined in turn with `--nsExclude`, `--nsInclude`, and `--excludeCollectionsWithPrefix`, and then restored again with two `--nsFrom`/`--nsTo` pairs that exchange a pair of databases. The swap case is the interesting one: mongorestore resolves every mapping against the original namespace and returns on the first match rather than chaining them, so applying the two pairs in sequence would send everything to one database, and the encoded `_id`s catch that. Each restored collection is also checked to have kept the index built over a field named for its source namespace, asserting the index key rather than just its name.
- `test/qa-tests/jstests/restore/multiple_dbs.js` -> `TestRestoreMultipleDBs` (`integration/dumprestore/namespace_test.go`) - two databases that share a collection name round-trip together and each ends up with exactly its own documents.
- `test/qa-tests/jstests/restore/partial_restore.js` -> `TestPartialRestore` (`integration/dumprestore/namespace_test.go`) - from a dump spanning two databases, restoring one database and then one collection leaves every namespace that was not asked for absent rather than merely empty.
- `test/legacy42/jstests/tool/dumprestore4.js` -> `TestRestoreIntoDifferentDBBuildsIndexes` (`integration/dumprestore/namespace_test.go`) - covers SERVER-2186: restoring a dump into a differently named database gives the destination the source's indexes, while a same-named database that happens to exist alongside it is left untouched.

One implementation note worth recording: `mongodump` accepts a single `--db` and has no `--nsInclude`, so a dump spanning several databases has to be assembled one database at a time into a shared root, which `withMultiDBDump` does. Dumping everything instead would sweep `admin` and `config` into the dump and then into the restores.
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_namespace_mapping_tests_to_go branch from e24c7be to ba45e6a Compare August 12, 2026 18:44
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.

1 participant