Skip to content

TOOLS-4263 Convert mongorestore index round-trip tests to Go - #1074

Open
autarch wants to merge 1 commit into
08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_gofrom
08-06-tools-4263_convert_mongorestore_index_round-trip_tests_to_go
Open

TOOLS-4263 Convert mongorestore index round-trip tests to Go#1074
autarch wants to merge 1 commit into
08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_gofrom
08-06-tools-4263_convert_mongorestore_index_round-trip_tests_to_go

Conversation

@autarch

@autarch autarch commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Adds integration/dumprestore/index_roundtrip_test.go: covering how mongorestore round-trips index specifications.

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

  • test/qa-tests/jstests/restore/indexes.js -> TestIndexRoundTrip (integration/dumprestore/index_roundtrip_test.go) - one collection carrying every index type the JS covered (simple, sparse and unique, compound, compound with int64 key values, multikey via array data, text with a non-default default_language, and 2dsphere) survives a dump/restore round trip, restored both from the dump directory and from the BSON file directly. The JS only compared index counts, so a mangled text-index weight or a dropped sparse flag would have gone unnoticed; this compares the complete spec of every index before and after, with fixture preconditions asserting the int64 key types and the Spanish text language really landed so that we're testing what we think we're testing. Note that the JS passed {language: 'spanish'}, which is not the createIndex option name and was therefore ignored by the server, so the Spanish text index is new coverage.
  • test/legacy42/jstests/tool/dumprestore6.js -> TestRestoreLegacySystemIndexes (integration/dumprestore/index_roundtrip_test.go) - a pre-2.6 dump stores index specs in a system.indexes.bson file rather than a per-collection metadata file, and mongorestore falls back to that file when a database directory has no metadata. The test builds such a dump at runtime, deliberately naming a different database in the specs' ns fields than the restore target so that mongorestore has to take the target from --db, then asserts the document and both indexes are created and the legacy v1 specs are converted to the current index version.
  • test/qa-tests/jstests/restore/index_version_roundtrip.js -> TestIndexVersionRoundTrip (integration/dumprestore/index_roundtrip_test.go) - --keepIndexVersion restores each _id index at its original version, while a restore without the flag gets the server's default version instead. Coverage is limited to _id indexes because the version can only be set through the create command's idIndex argument: a v1 secondary index is silently upgraded to the current version at creation on supported servers, so there is no secondary index version to round-trip. The secondary indexes are still created and asserted to survive both restores, along with the document counts.
  • test/qa-tests/jstests/restore/ordered_partial_index.js -> TestOrderedPartialIndex (integration/dumprestore/index_roundtrip_test.go) - an index whose partialFilterExpression has ten fields keeps that document's field order through the metadata file, since reordering it would produce an index the server treats as different from the one that was dumped. The fields are written in a deliberately unsorted order and the restored spec is read back as a bson.D, so both a sorted reordering and a randomized one are detectable; an ascending field list would have matched its own most likely corruption.

@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_index_round-trip_tests_to_go branch from dc89c96 to a464f74 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 08-06-tools-4263_convert_mongorestore_index_round-trip_tests_to_go branch from a464f74 to 9af89c7 Compare August 7, 2026 18:41
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_index_round-trip_tests_to_go branch from 9af89c7 to fa54faa 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 08-06-tools-4263_convert_mongorestore_index_round-trip_tests_to_go branch from fa54faa to 79a1fc6 Compare August 10, 2026 20:44
@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 force-pushed the 08-06-tools-4263_convert_mongorestore_index_round-trip_tests_to_go branch from 79a1fc6 to 7424f8b 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 bf6c0ab to e2915ba Compare August 11, 2026 17:11
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_index_round-trip_tests_to_go branch from 7424f8b to 871f7d6 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 2 times, most recently from a76dd71 to cdd0b30 Compare August 12, 2026 18:43
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_index_round-trip_tests_to_go branch 2 times, most recently from 1f368aa to 65e5458 Compare August 13, 2026 20:55
@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 21:01
@autarch
autarch marked this pull request as ready for review August 13, 2026 21:01
@autarch
autarch requested a review from a team as a code owner August 13, 2026 21:01
@autarch
autarch removed the request for review from a team August 14, 2026 16:31
@autarch
autarch marked this pull request as draft August 14, 2026 16:31
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_index_round-trip_tests_to_go branch from 65e5458 to f1b10a5 Compare August 14, 2026 16:43
@autarch
autarch force-pushed the 08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go branch from 1f88bc2 to 8bbfe97 Compare August 14, 2026 16:43
@autarch
autarch marked this pull request as ready for review August 14, 2026 16:52
@autarch
autarch marked this pull request as draft August 14, 2026 16:54
Adds `integration/dumprestore/index_roundtrip_test.go`: three `DumpRestoreSuite` methods, seven cases in total, covering how mongorestore round-trips index specifications. This also deletes two fixture directories that only the replaced JS tests used, `test/legacy42/jstests/tool/data/dumprestore6/` and `test/qa-tests/jstests/restore/testdata/dump_ordered_partial_index/`, since the Go tests build the equivalent dumps at runtime.

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

- `test/qa-tests/jstests/restore/indexes.js` -> `TestIndexRoundTrip` (`integration/dumprestore/index_roundtrip_test.go`) - one collection carrying every index type the JS covered (simple, sparse and unique, compound, compound with int64 key values, multikey via array data, text with a non-default `default_language`, and 2dsphere) survives a dump/restore round trip, restored both from the dump directory and from the BSON file directly. The JS only compared index counts, so a mangled text-index weight or a dropped sparse flag would have gone unnoticed; this compares the complete spec of every index before and after, with fixture preconditions asserting the int64 key types and the Spanish text language really landed so that comparison cannot go vacuous. Note that the JS passed `{language: 'spanish'}`, which is not the `createIndex` option name and was therefore ignored by the server, so the Spanish text index is new coverage.
- `test/legacy42/jstests/tool/dumprestore6.js` -> `TestIndexVersionRoundTrip`, the `a legacy system.indexes dump is converted` case (`integration/dumprestore/index_roundtrip_test.go`) - a pre-2.6 dump stores index specs in a `system.indexes.bson` file rather than a per-collection metadata file, and mongorestore falls back to that file when a database directory has no metadata. The test builds such a dump at runtime, deliberately naming a different database in the specs' `ns` fields than the restore target so that mongorestore has to take the target from `--db`, then asserts the document and both indexes are created and the legacy v1 specs are converted to the current index version.
- `test/qa-tests/jstests/restore/index_version_roundtrip.js` -> `TestIndexVersionRoundTrip` (`integration/dumprestore/index_roundtrip_test.go`) - `--keepIndexVersion` restores each `_id` index at its original version, while a restore without the flag gets the server's default version instead. Coverage is limited to `_id` indexes because the version can only be set through the create command's `idIndex` argument: a v1 secondary index is silently upgraded to the current version at creation on supported servers, so there is no secondary index version to round-trip. The secondary indexes are still created and asserted to survive both restores, along with the document counts.
- `test/qa-tests/jstests/restore/ordered_partial_index.js` -> `TestOrderedPartialIndex` (`integration/dumprestore/index_roundtrip_test.go`) - an index whose `partialFilterExpression` has ten fields keeps that document's field order through a real dump and restore, since reordering it would produce an index the server treats as different from the one that was dumped. The index is created on the server, dumped, dropped and restored, with the field order asserted before the dump as well so that a server which reordered the expression on its own could not make the test pass. The fields are given in a deliberately unsorted order and the restored spec is read back as a `bson.D`, so both a sorted reordering and a randomized one are detectable; an ascending field list would have matched its own most likely corruption.
@autarch
autarch force-pushed the 08-05-tools-4263_convert_mongorestore_collection-options_and_metadata_tests_to_go branch from 8bbfe97 to e14c2fe Compare August 14, 2026 19:02
@autarch
autarch force-pushed the 08-06-tools-4263_convert_mongorestore_index_round-trip_tests_to_go branch from f1b10a5 to 9d8cf10 Compare August 14, 2026 19:02
@autarch
autarch requested review from mmcclimon and removed request for mmcclimon August 14, 2026 19:05
@autarch
autarch marked this pull request as ready for review August 14, 2026 19:53
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