diff options
Diffstat (limited to 'src/mongo/gotools/test/qa-tests/jstests/bson/output_file.js')
-rw-r--r-- | src/mongo/gotools/test/qa-tests/jstests/bson/output_file.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/mongo/gotools/test/qa-tests/jstests/bson/output_file.js b/src/mongo/gotools/test/qa-tests/jstests/bson/output_file.js new file mode 100644 index 00000000000..1e339d6dcb1 --- /dev/null +++ b/src/mongo/gotools/test/qa-tests/jstests/bson/output_file.js @@ -0,0 +1,71 @@ +/** + * output_file.js + * + * This file tests outputting bsondump to a file when the input is from a file. + */ + +(function() { + 'use strict'; + + if (typeof getToolTest === 'undefined') { + load('jstests/configs/plain_28.config.js'); + } + + var toolTest = getToolTest('bson_output_file'); + var commonToolArgs = getCommonToolArguments(); + + // The db and collections we'll use. + var testDB = toolTest.db.getSiblingDB('test'); + var destColl = testDB.bsondump; + + // Test using a flag to specify the output file.. + var exportTarget = 'bson_dump.json'; + removeFile(exportTarget); + + var ret = _runMongoProgram("bsondump", + "--type=json", + "--bsonFile", "jstests/bson/testdata/sample.bson", + "--outFile", exportTarget); + assert.eq(ret, 0, "bsondump should exit successfully with 0"); + + // Import the data into the destination collection to check correctness. + ret = toolTest.runTool.apply(toolTest, ['import', + '--file', exportTarget, + '--db', 'test', + '--collection', 'bsondump', + '--type', 'json'] + .concat(commonToolArgs)); + assert.eq(0, ret); + + // Make sure everything was dumped. + assert.eq(1, destColl.count({a: 1.0})); + assert.eq(1, destColl.count({a: 2.5})); + assert.eq(1, destColl.count({a: 4.0})); + assert.eq(1, destColl.count({a: 4.01})); + + + // Test using a positional argument to specify the output file. + removeFile(exportTarget); + + ret = _runMongoProgram("bsondump", + "--type=json", + "--outFile", exportTarget, + "jstests/bson/testdata/sample.bson"); + assert.eq(ret, 0, "bsondump should exit successfully with 0"); + + // Import the data into the destination collection to check correctness. + ret = toolTest.runTool.apply(toolTest, ['import', + '--file', exportTarget, + '--db', 'test', + '--collection', 'bsondump', + '--type', 'json'] + .concat(commonToolArgs)); + assert.eq(0, ret); + + // Make sure everything was dumped. + assert.eq(1, destColl.count({a: 1.0})); + assert.eq(1, destColl.count({a: 2.5})); + assert.eq(1, destColl.count({a: 4.0})); + assert.eq(1, destColl.count({a: 4.01})); + +}()); |