summaryrefslogtreecommitdiff
path: root/src/mongo/gotools/src/github.com/mongodb/mongo-tools/test/qa-tests/jstests/top/mongotop_json.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/gotools/src/github.com/mongodb/mongo-tools/test/qa-tests/jstests/top/mongotop_json.js')
-rw-r--r--src/mongo/gotools/src/github.com/mongodb/mongo-tools/test/qa-tests/jstests/top/mongotop_json.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/test/qa-tests/jstests/top/mongotop_json.js b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/test/qa-tests/jstests/top/mongotop_json.js
new file mode 100644
index 00000000000..1828d578191
--- /dev/null
+++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/test/qa-tests/jstests/top/mongotop_json.js
@@ -0,0 +1,49 @@
+// mongotop_json.js; ensure that running mongotop using the --json flag works as
+// expected
+var testName = 'mongotop_json';
+(function() {
+ jsTest.log('Testing mongotop --json option');
+ load('jstests/top/util/mongotop_common.js');
+ var assert = extendedAssert;
+
+ var runTests = function(topology, passthrough) {
+ jsTest.log('Using ' + passthrough.name + ' passthrough');
+ var t = topology.init(passthrough);
+ var conn = t.connection();
+
+ // clear the output buffer
+ clearRawMongoProgramOutput();
+
+ // ensure tool runs without error with --rowcount = 1
+ var ret = executeProgram(['mongotop', '--port', conn.port, '--json', '--rowcount', 1].concat(passthrough.args));
+ assert.eq(ret.exitCode, 0, 'failed 1');
+ assert.eq.soon('object', function() {
+ return typeof JSON.parse(extractJSON(ret.getOutput()));
+ }, 'invalid JSON 1');
+
+ // ensure tool runs without error with --rowcount > 1
+ var rowcount = 5;
+ clearRawMongoProgramOutput();
+ ret = executeProgram(['mongotop', '--port', conn.port, '--json', '--rowcount', rowcount].concat(passthrough.args));
+ assert.eq(ret.exitCode, 0, 'failed 2');
+ var output;
+ assert.eq.soon(rowcount, function() {
+ output = ret.getOutput().split('\n');
+ if (jsTestOptions().useSSL) {
+ output = output.slice(1);
+ }
+ return output.length;
+ }, "expected " + rowcount + " top results");
+ output.forEach(function(line) {
+ assert(typeof JSON.parse(extractJSON(line)) === 'object', 'invalid JSON 2');
+ });
+
+ t.stop();
+ };
+
+ // run with plain and auth passthroughs
+ passthroughs.forEach(function(passthrough) {
+ runTests(standaloneTopology, passthrough);
+ runTests(replicaSetTopology, passthrough);
+ });
+}());