Skip to content

TOOLS-4263 Convert mongorestore drop, path and stdin tests to Go - #1096

Draft
autarch wants to merge 1 commit into
08-06-tools-4263_convert_mongorestore_namespace_mapping_tests_to_gofrom
08-07-tools-4263_convert_mongorestore_drop_path_and_stdin_tests_to_go
Draft

TOOLS-4263 Convert mongorestore drop, path and stdin tests to Go#1096
autarch wants to merge 1 commit into
08-06-tools-4263_convert_mongorestore_namespace_mapping_tests_to_gofrom
08-07-tools-4263_convert_mongorestore_drop_path_and_stdin_tests_to_go

Conversation

@autarch

@autarch autarch commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Adds integration/dumprestore/drop_test.go and integration/dumprestore/paths_test.go, extends TestPipedDumpRestore and TestRestoreInvalidInput, and deletes the seven JS tests they replace plus the symlink fixture that only one of them used.

JS -> Go mapping:

  • test/qa-tests/jstests/restore/drop_with_data.js -> TestRestoreDropWithData (integration/dumprestore/drop_test.go) - --drop replaces the existing contents of two collections. The pre-dump data is swapped for a disjoint set of documents with a different count before the restore, so a restore that upserted by _id rather than dropping leaves both sets behind and fails on content, not just on a count that happens to match.
  • test/qa-tests/jstests/restore/drop_one_collection.js -> TestRestoreDropOneCollection (integration/dumprestore/drop_test.go) - --drop scoped with --collection replaces only that collection, leaving its sibling and a second database holding the same collection names untouched.
  • test/qa-tests/jstests/restore/drop_nonexistent_db.js -> TestRestoreDropNonexistentDB (integration/dumprestore/drop_test.go) - --drop against a database that does not exist is not an error and restores normally.
  • test/qa-tests/jstests/restore/slash_in_collectionname.js -> TestRestoreSpecialCollectionNames (integration/dumprestore/paths_test.go) - collections named coll/foo, coll%bar and coll%2Fbaz round-trip through a directory-format dump, where the name has to survive being escaped into a filename and unescaped again. The third name is a double-escaping guard: if % ever stopped being escaped on the dump side, coll%2Fbaz would unescape back to coll/baz and restore into the wrong namespace.
  • test/qa-tests/jstests/restore/archive_stdout.js -> TestArchiveThroughStdout (integration/dumprestore/paths_test.go) - a real mongodump --archive process has its standard output piped into a real mongorestore --archive --drop process. TestPipedDumpRestore covers the archive format but connects the two in-process through an io.Pipe, so the CLI plumbing here (--archive with no value selecting stdout and stdin, and a binary archive surviving a real pipe) is not covered anywhere else.
  • test/qa-tests/jstests/restore/symlinks.js -> TestRestoreDumpWithSymlinks (integration/dumprestore/paths_test.go) - a dump directory in which a database directory and a collection's bson file are both symlinks restores correctly, and a symlink to a plain file at the top level is not walked as a database directory.
  • test/legacy42/jstests/tool/dumprestore1.js -> three subtests in TestRestoreInvalidInput (mongorestore/invalid_input_test.go) - a restore target of - reads from stdin, which carries no namespace of its own, so it is rejected with only --db, rejected with only --collection, and accepted with both. The accepting case matters: without it the two rejections would pass even if --dir - were rejected unconditionally.

Two things worth flagging for review.

The symlink fixture has no symlinks. Every entry under test/qa-tests/jstests/restore/testdata/dump_with_soft_links/ is a regular file (mode 100644), and the supposed link targets are duplicated blobs: dbOne/data.bson and soft_linked_collection.bson are the same object, as are dbTwo/data.bson and soft_linked_db/data.bson. The links were flattened into copies at some point, so symlinks.js has been exercising an ordinary dump directory. The Go test builds its dump with real symlinks at runtime, which makes it a coverage increase rather than a like-for-like port, and the fixture is deleted rather than carried forward.

TestPipedDumpRestore now verifies what it restored. It previously renamed every namespace and then asserted only that Restore() returned no error, never reading back a document, so a namespace dropped or misrouted by the archive demultiplexer would have gone unnoticed. It now checks every destination namespace.

@autarch
autarch force-pushed the 08-07-tools-4263_convert_mongorestore_drop_path_and_stdin_tests_to_go branch from 56c20e5 to dde6481 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-07-tools-4263_convert_mongorestore_drop_path_and_stdin_tests_to_go branch from dde6481 to 4f3a46b 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-07-tools-4263_convert_mongorestore_drop_path_and_stdin_tests_to_go branch from 4f3a46b to 330501c Compare August 11, 2026 16:19
@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-07-tools-4263_convert_mongorestore_drop_path_and_stdin_tests_to_go branch from 330501c to b73dae3 Compare August 11, 2026 17:11
@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
Adds `integration/dumprestore/drop_test.go` and `integration/dumprestore/paths_test.go`, extends `TestPipedDumpRestore` and `TestRestoreInvalidInput`, and deletes the seven JS tests they replace plus the symlink fixture that only one of them used.

JS -> Go mapping:

- `test/qa-tests/jstests/restore/drop_with_data.js` -> `TestRestoreDropWithData` (`integration/dumprestore/drop_test.go`) - `--drop` replaces the existing contents of two collections. The pre-dump data is swapped for a disjoint set of documents with a different count before the restore, so a restore that upserted by `_id` rather than dropping leaves both sets behind and fails on content, not just on a count that happens to match.
- `test/qa-tests/jstests/restore/drop_one_collection.js` -> `TestRestoreDropOneCollection` (`integration/dumprestore/drop_test.go`) - `--drop` scoped with `--collection` replaces only that collection, leaving its sibling and a second database holding the same collection names untouched.
- `test/qa-tests/jstests/restore/drop_nonexistent_db.js` -> `TestRestoreDropNonexistentDB` (`integration/dumprestore/drop_test.go`) - `--drop` against a database that does not exist is not an error and restores normally.
- `test/qa-tests/jstests/restore/slash_in_collectionname.js` -> `TestRestoreSpecialCollectionNames` (`integration/dumprestore/paths_test.go`) - collections named `coll/foo`, `coll%bar` and `coll%2Fbaz` round-trip through a directory-format dump, where the name has to survive being escaped into a filename and unescaped again. The third name is a double-escaping guard: if `%` ever stopped being escaped on the dump side, `coll%2Fbaz` would unescape back to `coll/baz` and restore into the wrong namespace.
- `test/qa-tests/jstests/restore/archive_stdout.js` -> `TestArchiveThroughStdout` (`integration/dumprestore/paths_test.go`) - a real `mongodump --archive` process has its standard output piped into a real `mongorestore --archive --drop` process. `TestPipedDumpRestore` covers the archive format but connects the two in-process through an `io.Pipe`, so the CLI plumbing here (`--archive` with no value selecting stdout and stdin, and a binary archive surviving a real pipe) is not covered anywhere else.
- `test/qa-tests/jstests/restore/symlinks.js` -> `TestRestoreDumpWithSymlinks` (`integration/dumprestore/paths_test.go`) - a dump directory in which a database directory and a collection's bson file are both symlinks restores correctly, and a symlink to a plain file at the top level is not walked as a database directory.
- `test/legacy42/jstests/tool/dumprestore1.js` -> three subtests in `TestRestoreInvalidInput` (`mongorestore/invalid_input_test.go`) - a restore target of `-` reads from stdin, which carries no namespace of its own, so it is rejected with only `--db`, rejected with only `--collection`, and accepted with both. The accepting case matters: without it the two rejections would pass even if `--dir -` were rejected unconditionally.

Two things worth flagging for review.

**The symlink fixture has no symlinks.** Every entry under `test/qa-tests/jstests/restore/testdata/dump_with_soft_links/` is a regular file (mode `100644`), and the supposed link targets are duplicated blobs: `dbOne/data.bson` and `soft_linked_collection.bson` are the same object, as are `dbTwo/data.bson` and `soft_linked_db/data.bson`. The links were flattened into copies at some point, so `symlinks.js` has been exercising an ordinary dump directory. The Go test builds its dump with real symlinks at runtime, which makes it a coverage increase rather than a like-for-like port, and the fixture is deleted rather than carried forward.

**`TestPipedDumpRestore` now verifies what it restored.** It previously renamed every namespace and then asserted only that `Restore()` returned no error, never reading back a document, so a namespace dropped or misrouted by the archive demultiplexer would have gone unnoticed. It now checks every destination namespace.
@autarch
autarch force-pushed the 08-07-tools-4263_convert_mongorestore_drop_path_and_stdin_tests_to_go branch from b73dae3 to 8c3b16c Compare August 12, 2026 18:45
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