Skip to content

TOOLS-4263 Convert mongorestore invalid-input tests to Go - #1046

Merged
autarch merged 1 commit into
masterfrom
07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go
Aug 12, 2026
Merged

TOOLS-4263 Convert mongorestore invalid-input tests to Go#1046
autarch merged 1 commit into
masterfrom
07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go

Conversation

@autarch

@autarch autarch commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Adds TestRestoreInvalidInput in mongorestore/invalid_input_test.go, covering mongorestore's handling of invalid options and invalid dump input. Each case asserts on the error returned by option validation or by Restore(), rather than on a process exit code. Every case is a named subtest function referenced from the parent, so the parent reads as a flat table of cases.

This also deletes the BSON/metadata fixtures under test/qa-tests/jstests/restore/testdata/ that only these JS tests used; the Go test writes the equivalent fixtures at runtime.

JS -> Go mapping (all Go subtests live in mongorestore/invalid_input_test.go under TestRestoreInvalidInput):

  • test/qa-tests/jstests/restore/bad_options.js -> testRestoreObjcheckWithNoobjcheck,
    testRestoreNegativeWriteConcern, testRestoreMalformedOplogLimit,
    testRestoreInvalidDBName, testRestoreInvalidCollectionName -Invalid option combinations and values are rejected: --objcheck together with the removed --noobjcheck flag, a negative --writeConcern, an --oplogLimit that is not a timestamp, a --db containing an illegal character, and a --collection containing an illegal character. (The JS test's -v torvalds verbosity case is intentionally not converted: verbosity parsing lives in the shared common/options package, not in mongorestore.)
  • test/qa-tests/jstests/restore/missing_dump.js -> testRestoreMissingDumpDirectory, testRestoreMissingDumpDirectoryWithDB, testRestoreMissingBSONFile - Restoring from a path that does not exist errors, whether it is a dump directory, a dump directory with --db, or a BSON file with --collection.
  • test/qa-tests/jstests/restore/invalid_dump_target.js -> testRestoreFileInsteadOfDirectory, testRestoreFileInsteadOfDBDirectory, testRestoreDirectoryInsteadOfBSONFile - Pointing mongorestore at the wrong kind of path errors: a plain file where a dump directory is expected (with and without --db), and a directory where a BSON file is expected.
  • test/qa-tests/jstests/restore/malformed_bson.js -> testRestoreMalformedBSON - A BSON file that is not valid BSON produces a read error rather than partial data.
  • test/qa-tests/jstests/restore/malformed_metadata.js -> testRestoreMalformedMetadata - A .metadata.json file that is not valid JSON produces a metadata parse error.
  • test/qa-tests/jstests/restore/invalid_metadata.js -> testRestoreInvalidIndexMetadata - Well-formed metadata containing an index spec the server rejects (an empty key document) produces an error.
  • test/qa-tests/jstests/restore/blank_collection_bson.js -> testRestoreBlankCollectionBSONWithoutMetadata, testRestoreBlankCollectionBSONWithMetadata - A zero-byte collection BSON file restores successfully and inserts nothing, both with and without an accompanying metadata file.
  • test/qa-tests/jstests/restore/blank_db.js -> testRestoreBlankDBDirectory - An empty database directory restores successfully and inserts nothing.
  • test/qa-tests/jstests/restore/objcheck_valid_bson.js -> testRestoreObjcheckValidBSON - --objcheck against valid BSON succeeds and restores every document.
  • test/qa-tests/jstests/restore/oplog_replay_no_oplog.js -> testRestoreOplogReplayNoOplogFile - --oplogReplay against a dump with no oplog.bson errors.

autarch commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

@autarch
autarch force-pushed the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch from 4fe13c9 to a8f11cc Compare July 16, 2026 20:27
@autarch
autarch force-pushed the 07-16-tools-4263_delete_js_tests_fully_covered_by_existing_go_tests branch from 75c4e40 to eef4eab Compare July 16, 2026 20:35
@autarch
autarch force-pushed the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch 2 times, most recently from ae94bd6 to ef8ebd0 Compare July 17, 2026 18:57
@autarch
autarch force-pushed the 07-16-tools-4263_delete_js_tests_fully_covered_by_existing_go_tests branch from eef4eab to 47590df Compare July 17, 2026 18:57
@autarch
autarch force-pushed the 07-16-tools-4263_delete_js_tests_fully_covered_by_existing_go_tests branch from 47590df to 5892362 Compare July 23, 2026 13:44
@autarch
autarch force-pushed the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch from ef8ebd0 to 0cea3b8 Compare July 23, 2026 13:44
@autarch
autarch force-pushed the 07-16-tools-4263_delete_js_tests_fully_covered_by_existing_go_tests branch from 5892362 to fcdfb84 Compare July 24, 2026 16:40
@autarch
autarch force-pushed the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch 3 times, most recently from 0566460 to 178b1c7 Compare July 24, 2026 18:51
@autarch
autarch force-pushed the 07-16-tools-4263_delete_js_tests_fully_covered_by_existing_go_tests branch from fcdfb84 to 523ab1e Compare July 27, 2026 21:16
@autarch
autarch force-pushed the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch from 178b1c7 to 1507db7 Compare July 27, 2026 21:17
@autarch
autarch changed the base branch from 07-16-tools-4263_delete_js_tests_fully_covered_by_existing_go_tests to graphite-base/1046 August 5, 2026 21:16
@autarch
autarch force-pushed the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch from 1507db7 to b058c9d Compare August 5, 2026 21:43
@autarch
autarch force-pushed the graphite-base/1046 branch from 523ab1e to 37b0e2c Compare August 5, 2026 21:43
@autarch
autarch changed the base branch from graphite-base/1046 to 07-16-tools-4263_delete_js_tests_fully_covered_by_existing_go_tests August 5, 2026 21:43

autarch commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

evergreen retry

@autarch
autarch force-pushed the 07-16-tools-4263_delete_js_tests_fully_covered_by_existing_go_tests branch from 37b0e2c to 95a5707 Compare August 5, 2026 21:47
@autarch
autarch force-pushed the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch from b058c9d to aaa2f97 Compare August 5, 2026 21:47
@autarch
autarch changed the base branch from 07-16-tools-4263_delete_js_tests_fully_covered_by_existing_go_tests to graphite-base/1046 August 6, 2026 19:55
@autarch
autarch force-pushed the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch from aaa2f97 to 556d7a4 Compare August 6, 2026 19:56
@autarch
autarch force-pushed the graphite-base/1046 branch from 95a5707 to cc6dd24 Compare August 6, 2026 19:56
@graphite-app
graphite-app Bot changed the base branch from graphite-base/1046 to master August 6, 2026 19:57
@autarch
autarch force-pushed the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch from 556d7a4 to 3faea21 Compare August 6, 2026 19:57
@autarch
autarch marked this pull request as ready for review August 7, 2026 15:23
@autarch
autarch requested a review from a team as a code owner August 7, 2026 15:23
@autarch
autarch requested review from Ronan-mongodb and mmcclimon and removed request for a team and Ronan-mongodb August 7, 2026 15:23
@autarch
autarch force-pushed the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch from 3faea21 to 4ce1d14 Compare August 7, 2026 18:41

@mmcclimon mmcclimon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Mostly LGTM, thanks.

Comment thread mongorestore/invalid_input_test.go Outdated
Comment on lines +67 to +68
// alongside --objcheck is now rejected as an unknown flag. The JS test's intent
// (the two flags cannot be combined) still holds.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This comment ("The JS test's intent") is weird.

Comment thread mongorestore/invalid_input_test.go Outdated
Comment on lines +22 to +32
// TestRestoreInvalidInput consolidates the mongorestore invalid-input and
// error-path coverage that previously lived in the qa-tests JS suite
// (bad_options.js, missing_dump.js, invalid_dump_target.js, malformed_bson.js,
// malformed_metadata.js, invalid_metadata.js, blank_collection_bson.js,
// blank_db.js, objcheck_valid_bson.js, oplog_replay_no_oplog.js). Each case
// asserts on the error returned by option validation or by Restore(), rather
// than on a process exit code.
//
// bad_options.js's invalid-verbosity case (-v torvalds) is intentionally not
// converted: verbosity parsing lives in the shared common/options package, not
// in mongorestore, so it is out of scope for these restore-specific tests.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think this comment is necessary.

Comment thread mongorestore/invalid_input_test.go Outdated
// writeBSONCollectionFile writes the given documents to path in the
// concatenated-BSON format that mongodump produces for a collection (an empty
// docs list produces a zero-byte file, i.e. a blank collection).
func writeBSONCollectionFile(t *testing.T, path string, docs ...bson.M) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's weird that these use bson.M and not bson.D (which we use everywhere else)

"dropping target collection",
)

const numDocs = 50

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(nit) This constant isn't wrong, but seems really weird to me, instead of just a variable.

Comment thread mongorestore/invalid_input_test.go Outdated

// restoreFromArgs builds a MongoRestore from the given args, runs it, and
// returns the result. The instance is closed when the test finishes.
func restoreFromArgs(t *testing.T, args ...string) Result {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This name is pretty confusing, imo; restoreFromArgs is very similar to the existing getRestoreWithArgs, but this function actually runs .Restore() on the mongorestore instance.

@autarch
autarch force-pushed the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch from 4ce1d14 to da61e5a Compare August 10, 2026 20:44
@autarch
autarch force-pushed the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch 2 times, most recently from 616ab13 to 4156951 Compare August 11, 2026 17:11

autarch commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

Merge activity

  • Aug 12, 6:36 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Aug 12, 6:37 PM UTC: Graphite rebased this pull request as part of a merge.
  • Aug 12, 6:38 PM UTC: @autarch merged this pull request with Graphite.

This adds a new `TestRestoreInvalidInput` test in `mongorestore/invalid_input_test.go`. This covers a number of cases for mongorestore's handling of invalid input options.

It replaces many JS tests:

- bad_options.js            -> "option validation" subtests: --objcheck
                               with --noobjcheck, malformed --oplogLimit,
                               negative --writeConcern, invalid --db,
                               invalid --collection. (The -v verbosity
                               case is omitted: it exercises shared
                               common/options code, not mongorestore.)
- missing_dump.js           -> "missing dump target" subtests (missing
                               dir, missing dir with --db, missing bson
                               file with --collection)
- invalid_dump_target.js    -> "invalid dump target" subtests (file where
                               a dir is expected, with and without --db;
                               dir where a bson file is expected)
- malformed_bson.js         -> "malformed bson file errors"
- malformed_metadata.js     -> "malformed metadata file errors"
- invalid_metadata.js       -> "invalid index in metadata errors"
- blank_collection_bson.js  -> "blank collection bson" subtests (with and
                               without a metadata file)
- blank_db.js               -> "blank db directory succeeds"
- objcheck_valid_bson.js    -> "objcheck succeeds on valid bson"
- oplog_replay_no_oplog.js  -> "oplogReplay with no oplog file errors"
@autarch
autarch force-pushed the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch from 4156951 to 6173adf Compare August 12, 2026 18:37
@autarch
autarch merged commit 3d78dc9 into master Aug 12, 2026
6 of 7 checks passed
@autarch
autarch deleted the 07-16-tools-4263_convert_mongorestore_invalid-input_tests_to_go branch August 12, 2026 18:38
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.

2 participants