Skip to content

TOOLS-4263 Convert mongorestore collection-options and metadata tests to Go - #1073

Open
autarch wants to merge 1 commit into
masterfrom
08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go
Open

TOOLS-4263 Convert mongorestore collection-options and metadata tests to Go#1073
autarch wants to merge 1 commit into
masterfrom
08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go

Conversation

@autarch

@autarch autarch commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Adds integration/dumprestore/options_roundtrip_test.go: covering how mongorestore handles collection options and dump metadata.

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

  • test/legacy42/jstests/tool/dumprestore8.js -> TestCappedCollectionRoundTrip (integration/dumprestore/options_roundtrip_test.go) - capped collection options and secondary indexes survive a dump/restore round trip. The fixture is a plain collection with two secondary indexes plus a capped collection that has already evicted documents, and it is restored four ways to cover each granularity: from the dump root, from a single database directory into a new database name, with --nsInclude db.*, and from a single BSON file into a new collection name. Each case checks document counts, index names, the capped options, and, most importantly, that the restored collection still evicts, by inserting past the cap and asserting the count does not grow.
  • test/qa-tests/jstests/restore/extended_json_metadata.js -> TestRestoreExtendedJSONMetadata (integration/dumprestore/options_roundtrip_test.go) - metadata written by very old versions of mongodump used legacy extended JSON types for numeric values, so the test hand-writes metadata in that shape, with {"$numberLong": ...} for the capped size and for an index's key, min, max, and bits, plus v: 1 indexes and an ns field, then asserts the capped options are restored and the index keys decode to plain values (_id -> 1, pos -> "2d") rather than to documents or strings. Modern mongodump cannot produce such a dump, so the fixture is built at runtime instead of being checked in, so now-unused testdata/dump_extended_json_options fixture is deleted.
  • test/qa-tests/jstests/restore/no_options_restore.js -> TestNoOptionsRestore (integration/dumprestore/options_roundtrip_test.go) - a default restore preserves collection options while --noOptionsRestore discards them, exercised against a fixture of one capped collection, one collection with a validator, and one collection with no options, all holding the same documents. In the stripped cases the restored collections are compared against the options an actual no-options collection reports on the same server, rather than against a hardcoded empty document, because servers add default option fields over time.
  • test/legacy42/jstests/tool/dumprestoreWithNoOptions.js -> TestNoOptionsRestore (integration/dumprestore/options_roundtrip_test.go) - --noOptionsRestore discards options at more than one granularity, covered by cases for a whole-dump restore and for a single-collection restore.
  • test/qa-tests/jstests/restore/collation.js -> TestCollationRoundTrip (integration/dumprestore/options_roundtrip_test.go) - a collection's default collation survives a round trip, restoring both from the dump directory and from the BSON file directly.
  • test/qa-tests/jstests/restore/restore_document_validation.js -> TestRestoreDocumentValidation (integration/dumprestore/options_roundtrip_test.go) - how restore interacts with document validation, in six cases: a validator on the target collection rejects the invalid half of the dump and mongorestore reports those as failures; --bypassDocumentValidation restores all of them; a validator carried in the dump's own metadata is recreated on restore and then rejects that same dump's invalid documents; --bypassDocumentValidation overrides even a validator restored that way; and --stopOnError and --maintainInsertionOrder each surface the validation error instead of swallowing it.
  • test/qa-tests/jstests/restore/norestore_profile.js -> TestSystemProfileIsNotRestored (integration/dumprestore/options_roundtrip_test.go) - mongorestore must skip a system.profile collection present in a dump. This test builds a dump containing system.profile.bson and its metadata by hand, because mongodump will always skip the system.profile collection. Then it asserts the user data is restored, system.profile is not created, and mongorestore reports zero failed inserts, the last of which is what distinguishes mongorestore skipping the file from mongorestore attempting the insert and the server rejecting it.

@autarch
autarch force-pushed the 08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go branch from d387e39 to b140e6a Compare August 5, 2026 21:47
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from 6108e99 to d36edee Compare August 5, 2026 21:47
@autarch
autarch force-pushed the 08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go branch from b140e6a to 4f8a684 Compare August 5, 2026 21:48
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from d36edee to b2f3635 Compare August 6, 2026 21:25
@autarch
autarch force-pushed the 08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go branch from 4f8a684 to 7aae4fa Compare August 6, 2026 21:25
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from b2f3635 to dee6aeb Compare August 7, 2026 18:41
@autarch
autarch force-pushed the 08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go branch from 7aae4fa to fe29406 Compare August 7, 2026 18:42
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from dee6aeb to 51f2499 Compare August 7, 2026 18:57
@autarch
autarch force-pushed the 08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go branch 2 times, most recently from f741073 to 8caf2b8 Compare August 10, 2026 20:44
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from 51f2499 to 5bc5a26 Compare August 10, 2026 20:44
@autarch
autarch changed the base branch from 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go to graphite-base/1073 August 10, 2026 21:22
@autarch
autarch force-pushed the graphite-base/1073 branch from 5bc5a26 to c7741dd Compare August 11, 2026 16:19
@autarch
autarch force-pushed the 08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go branch from 8caf2b8 to bf6c0ab Compare August 11, 2026 16:19
@autarch
autarch changed the base branch from graphite-base/1073 to 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go August 11, 2026 16:19
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from c7741dd to ec6cd0a Compare August 11, 2026 17:11
@autarch
autarch force-pushed the 08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go branch from bf6c0ab to e2915ba Compare August 11, 2026 17:11
@autarch
autarch changed the base branch from 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go to graphite-base/1073 August 12, 2026 18:41
@autarch
autarch force-pushed the graphite-base/1073 branch from ec6cd0a to a069aa5 Compare August 12, 2026 18:42
@autarch
autarch force-pushed the 08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go branch from e2915ba to a76dd71 Compare August 12, 2026 18:42
@graphite-app
graphite-app Bot changed the base branch from graphite-base/1073 to master August 12, 2026 18:43
@autarch
autarch force-pushed the 08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go branch from a76dd71 to cdd0b30 Compare August 12, 2026 18:43
… to Go

Adds `integration/dumprestore/options_roundtrip_test.go`: six `DumpRestoreSuite` methods, 18 cases in total, covering how mongorestore handles collection options and dump metadata.

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

- `test/legacy42/jstests/tool/dumprestore8.js` -> `TestCappedCollectionRoundTrip` (`integration/dumprestore/options_roundtrip_test.go`) - capped collection options, secondary indexes, and eviction behavior survive a dump/restore round trip. The fixture is a plain collection with two secondary indexes plus a capped collection that has already evicted documents, and it is restored four ways to cover each granularity: from the dump root, from a single database directory into a new database name, with `--nsInclude db.*`, and from a single BSON file into a new collection name. Each case checks document counts, index names, the capped options, and, most importantly, that the restored collection still evicts, by inserting past the cap and asserting the count does not grow.
- `test/qa-tests/jstests/restore/extended_json_metadata.js` -> `TestRestoreExtendedJSONMetadata` (`integration/dumprestore/options_roundtrip_test.go`) - metadata written by very old versions of mongodump used legacy extended JSON types for numeric values, so the test hand-writes metadata in that shape, with `{"$numberLong": ...}` for the capped `size` and for an index's `key`, `min`, `max`, and `bits`, plus `v: 1` indexes and an `ns` field, then asserts the capped options are restored and the index keys decode to plain values (`_id -> 1`, `pos -> "2d"`) rather than to documents or strings. Modern mongodump cannot produce such a dump, so the fixture is built at runtime instead of being checked in, which also lets the now-unused `testdata/dump_extended_json_options` fixture go away.
- `test/qa-tests/jstests/restore/no_options_restore.js` -> `TestNoOptionsRestore` (`integration/dumprestore/options_roundtrip_test.go`) - a default restore preserves collection options while `--noOptionsRestore` discards them, exercised against a fixture of one capped collection, one collection with a validator, and one collection with no options, all holding the same documents. In the stripped cases the restored collections are compared against the options an actual no-options collection reports on the same server, rather than against a hardcoded empty document, because servers add default option fields over time.
- `test/legacy42/jstests/tool/dumprestoreWithNoOptions.js` -> `TestNoOptionsRestore` (`integration/dumprestore/options_roundtrip_test.go`) - `--noOptionsRestore` discards options at more than one granularity, covered by cases for a whole-dump restore and for a single-collection restore.
- `test/qa-tests/jstests/restore/collation.js` -> `TestCollationRoundTrip` (`integration/dumprestore/options_roundtrip_test.go`) - a collection's default collation survives a round trip, restoring both from the dump directory and from the BSON file directly.
- `test/qa-tests/jstests/restore/restore_document_validation.js` -> `TestRestoreDocumentValidation` (`integration/dumprestore/options_roundtrip_test.go`) - how restore interacts with document validation, in six cases: a validator on the target collection rejects the invalid half of the dump and mongorestore reports those as failures; `--bypassDocumentValidation` restores all of them; a validator carried in the dump's own metadata is recreated on restore and then rejects that same dump's invalid documents; `--bypassDocumentValidation` overrides even a validator restored that way; and `--stopOnError` and `--maintainInsertionOrder` each surface the validation error instead of swallowing it.
- `test/qa-tests/jstests/restore/norestore_profile.js` -> `TestSystemProfileIsNotRestored` (`integration/dumprestore/options_roundtrip_test.go`) - mongorestore must skip a `system.profile` collection present in a dump. The JS test could never actually reach that check, because mongodump skips every `<db>.system.*` namespace, so the dump it took contained no `system.profile.bson` and the assertion passed vacuously; the Go test instead builds a dump containing `system.profile.bson` and its metadata by hand, then asserts the user data is restored, `system.profile` is not created, and mongorestore reports zero failed inserts, the last of which is what distinguishes mongorestore skipping the file from mongorestore attempting the insert and the server rejecting it.
@autarch
autarch force-pushed the 08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go branch from cdd0b30 to 1f88bc2 Compare August 13, 2026 20:55
@autarch
autarch requested a review from mmcclimon August 13, 2026 20:58
@autarch
autarch marked this pull request as ready for review August 13, 2026 20:58
@autarch
autarch requested a review from a team as a code owner August 13, 2026 20:58
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