summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun Verch <shaun.verch@mongodb.com>2014-04-15 16:37:13 -0400
committerDan Pasette <dan@mongodb.com>2014-05-16 20:00:07 -0400
commit013e21bbe58c4d345df61576fb3cafe41c2ae49c (patch)
tree007dbf1c8e3fce263ba25ee8ebaa6205a3e3e6e4
parent195a67eec3cf8a337b5f524d138206e83bf564d4 (diff)
downloadmongo-013e21bbe58c4d345df61576fb3cafe41c2ae49c.tar.gz
SERVER-13603 Move option testing support code into shared test helper
(cherry picked from commit f7d78f9511d3e4fa156d6f94322f5a690a21bc20)
-rw-r--r--jstests/auth/auth_options.js36
-rw-r--r--jstests/core/test_command_line_test_helpers.js6
-rw-r--r--jstests/disk/datafile_options.js35
-rw-r--r--jstests/disk/index_options.js34
-rw-r--r--jstests/dur/journaling_options.js70
-rw-r--r--jstests/libs/command_line/test_parsed_options.js202
-rw-r--r--jstests/noPassthrough/logging_options.js46
-rw-r--r--jstests/noPassthrough/network_options.js57
-rw-r--r--jstests/noPassthrough/profile_options.js38
-rw-r--r--jstests/repl/repl_options.js40
-rw-r--r--jstests/sharding/sharding_options.js65
11 files changed, 279 insertions, 350 deletions
diff --git a/jstests/auth/auth_options.js b/jstests/auth/auth_options.js
index 36a76449f4b..ad694df7413 100644
--- a/jstests/auth/auth_options.js
+++ b/jstests/auth/auth_options.js
@@ -1,32 +1,6 @@
var baseName = "jstests_auth_auth_options";
-function removeOptionsAddedByFramework(getCmdLineOptsResult) {
- // Remove options that we are not interested in checking, but that get set by the test
- delete getCmdLineOptsResult.parsed.setParameter
- delete getCmdLineOptsResult.parsed.storage
- delete getCmdLineOptsResult.parsed.net
- delete getCmdLineOptsResult.parsed.fastsync
- return getCmdLineOptsResult;
-}
-
-function testGetCmdLineOpts(mongoRunnerConfig, expectedResult) {
-
- // Start mongod with options
- var mongod = MongoRunner.runMongod(mongoRunnerConfig);
-
- // Get the parsed options
- var getCmdLineOptsResult = mongod.adminCommand("getCmdLineOpts");
- printjson(getCmdLineOptsResult);
-
- // Remove options added by the test framework
- getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-
- // Make sure the options are equal to what we expect
- assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);
-
- // Cleanup
- MongoRunner.stopMongod(mongod.port);
-}
+load('jstests/libs/command_line/test_parsed_options.js');
jsTest.log("Testing \"auth\" command line option");
var expectedResult = {
@@ -36,7 +10,7 @@ var expectedResult = {
}
}
};
-testGetCmdLineOpts({ auth : "" }, expectedResult);
+testGetCmdLineOptsMongod({ auth : "" }, expectedResult);
jsTest.log("Testing \"noauth\" command line option");
expectedResult = {
@@ -46,7 +20,7 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ noauth : "" }, expectedResult);
+testGetCmdLineOptsMongod({ noauth : "" }, expectedResult);
jsTest.log("Testing \"security.authorization\" config file option");
expectedResult = {
@@ -57,12 +31,12 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ config : "jstests/libs/config_files/enable_auth.json" }, expectedResult);
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/enable_auth.json" }, expectedResult);
jsTest.log("Testing with no explicit object check setting");
expectedResult = {
"parsed" : { }
};
-testGetCmdLineOpts({}, expectedResult);
+testGetCmdLineOptsMongod({}, expectedResult);
print(baseName + " succeeded.");
diff --git a/jstests/core/test_command_line_test_helpers.js b/jstests/core/test_command_line_test_helpers.js
new file mode 100644
index 00000000000..a66bd713327
--- /dev/null
+++ b/jstests/core/test_command_line_test_helpers.js
@@ -0,0 +1,6 @@
+load('jstests/libs/command_line/test_parsed_options.js');
+
+assert.docEq({ x : 1, y : 1 }, mergeOptions({ x : 1 }, { y : 1 }));
+assert.docEq({ x : 1, y : 1 }, mergeOptions({ x : 1, y : 2 }, { y : 1 }));
+assert.docEq({ x : { z : 1 }, y : 1 }, mergeOptions({ x : { z : 1 } }, { y : 1 }));
+assert.docEq({ x : { z : 1 } }, mergeOptions({ x : { z : 2 } }, { x : { z : 1 } }));
diff --git a/jstests/disk/datafile_options.js b/jstests/disk/datafile_options.js
index 88933ad4845..36a3de3663c 100644
--- a/jstests/disk/datafile_options.js
+++ b/jstests/disk/datafile_options.js
@@ -1,32 +1,6 @@
var baseName = "jstests_disk_datafile_options";
-function removeOptionsAddedByFramework(getCmdLineOptsResult) {
- // Remove options that we are not interested in checking, but that get set by the test
- delete getCmdLineOptsResult.parsed.setParameter
- delete getCmdLineOptsResult.parsed.storage.dbPath
- delete getCmdLineOptsResult.parsed.net
- delete getCmdLineOptsResult.parsed.fastsync
- return getCmdLineOptsResult;
-}
-
-function testGetCmdLineOpts(mongoRunnerConfig, expectedResult) {
-
- // Start mongod with options
- var mongod = MongoRunner.runMongod(mongoRunnerConfig);
-
- // Get the parsed options
- var getCmdLineOptsResult = mongod.adminCommand("getCmdLineOpts");
- printjson(getCmdLineOptsResult);
-
- // Remove options added by the test framework
- getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-
- // Make sure the options are equal to what we expect
- assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);
-
- // Cleanup
- MongoRunner.stopMongod(mongod.port);
-}
+load('jstests/libs/command_line/test_parsed_options.js');
jsTest.log("Testing \"noprealloc\" command line option");
var expectedResult = {
@@ -36,7 +10,7 @@ var expectedResult = {
}
}
};
-testGetCmdLineOpts({ noprealloc : "" }, expectedResult);
+testGetCmdLineOptsMongod({ noprealloc : "" }, expectedResult);
jsTest.log("Testing \"storage.preallocDataFiles\" config file option");
expectedResult = {
@@ -47,7 +21,8 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ config : "jstests/libs/config_files/enable_prealloc.json" }, expectedResult);
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/enable_prealloc.json" },
+ expectedResult);
jsTest.log("Testing with no explicit data file option setting");
expectedResult = {
@@ -55,6 +30,6 @@ expectedResult = {
"storage" : { }
}
};
-testGetCmdLineOpts({}, expectedResult);
+testGetCmdLineOptsMongod({}, expectedResult);
print(baseName + " succeeded.");
diff --git a/jstests/disk/index_options.js b/jstests/disk/index_options.js
index a6ef4a37d56..0624d93b21e 100644
--- a/jstests/disk/index_options.js
+++ b/jstests/disk/index_options.js
@@ -1,32 +1,6 @@
var baseName = "jstests_disk_index_options";
-function removeOptionsAddedByFramework(getCmdLineOptsResult) {
- // Remove options that we are not interested in checking, but that get set by the test
- delete getCmdLineOptsResult.parsed.setParameter
- delete getCmdLineOptsResult.parsed.storage.dbPath
- delete getCmdLineOptsResult.parsed.net
- delete getCmdLineOptsResult.parsed.fastsync
- return getCmdLineOptsResult;
-}
-
-function testGetCmdLineOpts(mongoRunnerConfig, expectedResult) {
-
- // Start mongod with options
- var mongod = MongoRunner.runMongod(mongoRunnerConfig);
-
- // Get the parsed options
- var getCmdLineOptsResult = mongod.adminCommand("getCmdLineOpts");
- printjson(getCmdLineOptsResult);
-
- // Remove options added by the test framework
- getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-
- // Make sure the options are equal to what we expect
- assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);
-
- // Cleanup
- MongoRunner.stopMongod(mongod.port);
-}
+load('jstests/libs/command_line/test_parsed_options.js');
jsTest.log("Testing \"noIndexBuildRetry\" command line option");
var expectedResult = {
@@ -36,7 +10,7 @@ var expectedResult = {
}
}
};
-testGetCmdLineOpts({ noIndexBuildRetry : "" }, expectedResult);
+testGetCmdLineOptsMongod({ noIndexBuildRetry : "" }, expectedResult);
jsTest.log("Testing \"storage.indexBuildRetry\" config file option");
expectedResult = {
@@ -47,7 +21,7 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ config : "jstests/libs/config_files/enable_indexbuildretry.json" },
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/enable_indexbuildretry.json" },
expectedResult);
jsTest.log("Testing with no explicit index option setting");
@@ -56,6 +30,6 @@ expectedResult = {
"storage" : { }
}
};
-testGetCmdLineOpts({}, expectedResult);
+testGetCmdLineOptsMongod({}, expectedResult);
print(baseName + " succeeded.");
diff --git a/jstests/dur/journaling_options.js b/jstests/dur/journaling_options.js
index 1c62c2167b0..a457882fffe 100644
--- a/jstests/dur/journaling_options.js
+++ b/jstests/dur/journaling_options.js
@@ -1,17 +1,9 @@
var baseName = "jstests_dur_journaling_options";
-function removeOptionsAddedByFramework(getCmdLineOptsResult) {
- // Remove options that we are not interested in checking, but that get set by the test
- delete getCmdLineOptsResult.parsed.setParameter
- delete getCmdLineOptsResult.parsed.storage.dbPath
- delete getCmdLineOptsResult.parsed.net
- delete getCmdLineOptsResult.parsed.fastsync
- return getCmdLineOptsResult;
-}
+load('jstests/libs/command_line/test_parsed_options.js');
jsTest.log("Testing \"dur\" command line option");
-var mongodSource = MongoRunner.runMongod({ dur : "" });
-var getCmdLineOptsExpected = {
+var expectedResult = {
"parsed" : {
"storage" : {
"journal" : {
@@ -20,16 +12,10 @@ var getCmdLineOptsExpected = {
}
}
};
-
-var getCmdLineOptsResult = mongodSource.adminCommand("getCmdLineOpts");
-printjson(getCmdLineOptsResult);
-getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-assert.docEq(getCmdLineOptsResult.parsed, getCmdLineOptsExpected.parsed);
-MongoRunner.stopMongod(mongodSource.port);
+testGetCmdLineOptsMongod({ dur : "" }, expectedResult);
jsTest.log("Testing \"nodur\" command line option");
-mongodSource = MongoRunner.runMongod({ nodur : "" });
-getCmdLineOptsExpected = {
+expectedResult = {
"parsed" : {
"storage" : {
"journal" : {
@@ -38,16 +24,10 @@ getCmdLineOptsExpected = {
}
}
};
-
-getCmdLineOptsResult = mongodSource.adminCommand("getCmdLineOpts");
-printjson(getCmdLineOptsResult);
-getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-assert.docEq(getCmdLineOptsResult.parsed, getCmdLineOptsExpected.parsed);
-MongoRunner.stopMongod(mongodSource.port);
+testGetCmdLineOptsMongod({ nodur : "" }, expectedResult);
jsTest.log("Testing \"journal\" command line option");
-mongodSource = MongoRunner.runMongod({ journal : "" });
-getCmdLineOptsExpected = {
+expectedResult = {
"parsed" : {
"storage" : {
"journal" : {
@@ -56,16 +36,10 @@ getCmdLineOptsExpected = {
}
}
};
-
-getCmdLineOptsResult = mongodSource.adminCommand("getCmdLineOpts");
-printjson(getCmdLineOptsResult);
-getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-assert.docEq(getCmdLineOptsResult.parsed, getCmdLineOptsExpected.parsed);
-MongoRunner.stopMongod(mongodSource.port);
+testGetCmdLineOptsMongod({ journal : "" }, expectedResult);
jsTest.log("Testing \"nojournal\" command line option");
-mongodSource = MongoRunner.runMongod({ nojournal : "" });
-getCmdLineOptsExpected = {
+expectedResult = {
"parsed" : {
"storage" : {
"journal" : {
@@ -74,16 +48,10 @@ getCmdLineOptsExpected = {
}
}
};
-
-getCmdLineOptsResult = mongodSource.adminCommand("getCmdLineOpts");
-printjson(getCmdLineOptsResult);
-getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-assert.docEq(getCmdLineOptsResult.parsed, getCmdLineOptsExpected.parsed);
-MongoRunner.stopMongod(mongodSource.port);
+testGetCmdLineOptsMongod({ nojournal : "" }, expectedResult);
jsTest.log("Testing \"storage.journal.enabled\" config file option");
-mongodSource = MongoRunner.runMongod({ config : "jstests/libs/config_files/enable_journal.json" });
-getCmdLineOptsExpected = {
+expectedResult = {
"parsed" : {
"config" : "jstests/libs/config_files/enable_journal.json",
"storage" : {
@@ -93,25 +61,15 @@ getCmdLineOptsExpected = {
}
}
};
-
-getCmdLineOptsResult = mongodSource.adminCommand("getCmdLineOpts");
-printjson(getCmdLineOptsResult);
-getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-assert.docEq(getCmdLineOptsResult.parsed, getCmdLineOptsExpected.parsed);
-MongoRunner.stopMongod(mongodSource.port);
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/enable_journal.json" },
+ expectedResult);
jsTest.log("Testing with no explicit journal setting");
-mongodSource = MongoRunner.runMongod();
-getCmdLineOptsExpected = {
+expectedResult = {
"parsed" : {
"storage" : { }
}
};
-
-getCmdLineOptsResult = mongodSource.adminCommand("getCmdLineOpts");
-printjson(getCmdLineOptsResult);
-getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-assert.docEq(getCmdLineOptsResult.parsed, getCmdLineOptsExpected.parsed);
-MongoRunner.stopMongod(mongodSource.port);
+testGetCmdLineOptsMongod({}, expectedResult);
print(baseName + " succeeded.");
diff --git a/jstests/libs/command_line/test_parsed_options.js b/jstests/libs/command_line/test_parsed_options.js
new file mode 100644
index 00000000000..e2ca646b63a
--- /dev/null
+++ b/jstests/libs/command_line/test_parsed_options.js
@@ -0,0 +1,202 @@
+// Merge the two options objects. Used as a helper when we are trying to actually compare options
+// despite the fact that our test framework adds extra stuff to it. Anything set in the second
+// options object overrides the first options object. The two objects must have the same structure.
+function mergeOptions(obj1, obj2) {
+ var obj3 = {};
+ for (var attrname in obj1) {
+ if (typeof obj1[attrname] === "object" &&
+ typeof obj2[attrname] !== "undefined") {
+ if (typeof obj2[attrname] !== "object") {
+ throw "Objects being merged must have the same structure";
+ }
+ obj3[attrname] = mergeOptions(obj1[attrname], obj2[attrname]);
+ }
+ else {
+ obj3[attrname] = obj1[attrname];
+ }
+ }
+ for (var attrname in obj2) {
+ if (typeof obj2[attrname] === "object" &&
+ typeof obj1[attrname] !== "undefined") {
+ if (typeof obj1[attrname] !== "object") {
+ throw "Objects being merged must have the same structure";
+ }
+ // Already handled above
+ }
+ else {
+ obj3[attrname] = obj2[attrname];
+ }
+ }
+ return obj3;
+}
+
+// Test that the parsed result of setting certain command line options has the correct format in
+// mongod. See SERVER-13379.
+//
+// Arguments:
+// mongoRunnerConfig - Configuration object to pass to the mongo runner
+// expectedResult - Object formatted the same way as the result of running the "getCmdLineOpts"
+// command, but with only the fields that should be set by the options implied by the first
+// argument set.
+//
+// Example:
+//
+// testGetCmdLineOptsMongod({ port : 10000 }, { "parsed" : { "net" : { "port" : 10000 } } });
+//
+var getCmdLineOptsBaseMongod;
+function testGetCmdLineOptsMongod(mongoRunnerConfig, expectedResult) {
+
+ // Get the options object returned by "getCmdLineOpts" when we spawn a mongod using our test
+ // framework without passing any additional options. We need this because the framework adds
+ // options of its own, and we only want to compare against the options we care about.
+ function getBaseOptsObject() {
+
+ // Start mongod with no options
+ var baseMongod = MongoRunner.runMongod();
+
+ // Get base command line opts. Needed because the framework adds its own options
+ var getCmdLineOptsBaseMongod = baseMongod.adminCommand("getCmdLineOpts");
+
+ // Stop the mongod we used to get the options
+ MongoRunner.stopMongod(baseMongod.port);
+
+ return getCmdLineOptsBaseMongod;
+ }
+
+ if (typeof getCmdLineOptsBaseMongod === "undefined") {
+ getCmdLineOptsBaseMongod = getBaseOptsObject();
+ }
+
+ // Get base command line opts. Needed because the framework adds its own options
+ var getCmdLineOptsExpected = getCmdLineOptsBaseMongod;
+
+ // Delete port and dbPath if we are not explicitly setting them, since they will change on
+ // multiple runs of the test framework and cause false failures.
+ if (typeof expectedResult.parsed === "undefined" ||
+ typeof expectedResult.parsed.net === "undefined" ||
+ typeof expectedResult.parsed.net.port === "undefined") {
+ delete getCmdLineOptsExpected.parsed.net.port;
+ }
+ if (typeof expectedResult.parsed === "undefined" ||
+ typeof expectedResult.parsed.storage === "undefined" ||
+ typeof expectedResult.parsed.storage.dbPath === "undefined") {
+ delete getCmdLineOptsExpected.parsed.storage.dbPath;
+ }
+
+ // Merge with the result that we expect
+ expectedResult = mergeOptions(getCmdLineOptsExpected, expectedResult);
+
+ // Start mongod with options
+ var mongod = MongoRunner.runMongod(mongoRunnerConfig);
+
+ // Get the parsed options
+ var getCmdLineOptsResult = mongod.adminCommand("getCmdLineOpts");
+
+ // Delete port and dbPath if we are not explicitly setting them, since they will change on
+ // multiple runs of the test framework and cause false failures.
+ if (typeof expectedResult.parsed === "undefined" ||
+ typeof expectedResult.parsed.net === "undefined" ||
+ typeof expectedResult.parsed.net.port === "undefined") {
+ delete getCmdLineOptsResult.parsed.net.port;
+ }
+ if (typeof expectedResult.parsed === "undefined" ||
+ typeof expectedResult.parsed.storage === "undefined" ||
+ typeof expectedResult.parsed.storage.dbPath === "undefined") {
+ delete getCmdLineOptsResult.parsed.storage.dbPath;
+ }
+
+ // Make sure the options are equal to what we expect
+ assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);
+
+ // Cleanup
+ MongoRunner.stopMongod(mongod.port);
+}
+
+// Test that the parsed result of setting certain command line options has the correct format in
+// mongos. See SERVER-13379.
+//
+// Arguments:
+// mongoRunnerConfig - Configuration object to pass to the mongo runner
+// expectedResult - Object formatted the same way as the result of running the "getCmdLineOpts"
+// command, but with only the fields that should be set by the options implied by the first
+// argument set.
+//
+// Example:
+//
+// testGetCmdLineOptsMongos({ port : 10000 }, { "parsed" : { "net" : { "port" : 10000 } } });
+//
+var getCmdLineOptsBaseMongos;
+function testGetCmdLineOptsMongos(mongoRunnerConfig, expectedResult) {
+
+ // Get the options object returned by "getCmdLineOpts" when we spawn a mongos using our test
+ // framework without passing any additional options. We need this because the framework adds
+ // options of its own, and we only want to compare against the options we care about.
+ function getBaseOptsObject() {
+
+ // Start mongod with no options
+ var baseMongod = MongoRunner.runMongod();
+
+ // Start mongos with only the configdb option
+ var baseMongos = MongoRunner.runMongos({ configdb : baseMongod.host });
+
+ // Get base command line opts. Needed because the framework adds its own options
+ var getCmdLineOptsBaseMongos = baseMongos.adminCommand("getCmdLineOpts");
+
+ // Remove the configdb option
+ delete getCmdLineOptsBaseMongos.parsed.sharding.configDB;
+
+ // Stop the mongod and mongos we used to get the options
+ MongoRunner.stopMongos(baseMongos.port);
+ MongoRunner.stopMongod(baseMongod.port);
+
+ return getCmdLineOptsBaseMongos;
+ }
+
+ if (typeof getCmdLineOptsBaseMongos === "undefined") {
+ getCmdLineOptsBaseMongos = getBaseOptsObject();
+ }
+
+ // Get base command line opts. Needed because the framework adds its own options
+ var getCmdLineOptsExpected = getCmdLineOptsBaseMongos;
+
+ // Delete port if we are not explicitly setting it, since it will change on multiple runs of the
+ // test framework and cause false failures.
+ if (typeof expectedResult.parsed === "undefined" ||
+ typeof expectedResult.parsed.net === "undefined" ||
+ typeof expectedResult.parsed.net.port === "undefined") {
+ delete getCmdLineOptsExpected.parsed.net.port;
+ }
+
+ // Merge with the result that we expect
+ expectedResult = mergeOptions(getCmdLineOptsExpected, expectedResult);
+
+ // Start mongod with no options
+ var mongod = MongoRunner.runMongod();
+
+ // Add configdb option
+ mongoRunnerConfig['configdb'] = mongod.host;
+
+ // Start mongos connected to mongod
+ var mongos = MongoRunner.runMongos(mongoRunnerConfig);
+
+ // Get the parsed options
+ var getCmdLineOptsResult = mongos.adminCommand("getCmdLineOpts");
+
+ // Delete port if we are not explicitly setting it, since it will change on multiple runs of the
+ // test framework and cause false failures.
+ if (typeof expectedResult.parsed === "undefined" ||
+ typeof expectedResult.parsed.net === "undefined" ||
+ typeof expectedResult.parsed.net.port === "undefined") {
+ delete getCmdLineOptsResult.parsed.net.port;
+ }
+
+ // Remove the configdb option
+ delete getCmdLineOptsResult.parsed.sharding.configDB;
+
+ // Make sure the options are equal to what we expect
+ assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);
+
+ // Cleanup
+ MongoRunner.stopMongos(mongos.port);
+ MongoRunner.stopMongod(mongod.port);
+}
diff --git a/jstests/noPassthrough/logging_options.js b/jstests/noPassthrough/logging_options.js
index b3d999a53a8..241dcdb42b2 100644
--- a/jstests/noPassthrough/logging_options.js
+++ b/jstests/noPassthrough/logging_options.js
@@ -1,33 +1,6 @@
var baseName = "jstests_core_logging_options";
-function removeOptionsAddedByFramework(getCmdLineOptsResult) {
- // Remove options that we are not interested in checking, but that get set by the test
- delete getCmdLineOptsResult.parsed.setParameter
- delete getCmdLineOptsResult.parsed.storage
- delete getCmdLineOptsResult.parsed.net
- delete getCmdLineOptsResult.parsed.fastsync
- delete getCmdLineOptsResult.parsed.security
- return getCmdLineOptsResult;
-}
-
-function testGetCmdLineOpts(mongoRunnerConfig, expectedResult) {
-
- // Start mongod with options
- var mongod = MongoRunner.runMongod(mongoRunnerConfig);
-
- // Get the parsed options
- var getCmdLineOptsResult = mongod.adminCommand("getCmdLineOpts");
- printjson(getCmdLineOptsResult);
-
- // Remove options added by the test framework
- getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-
- // Make sure the options are equal to what we expect
- assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);
-
- // Cleanup
- MongoRunner.stopMongod(mongod.port);
-}
+load('jstests/libs/command_line/test_parsed_options.js');
// Verbosity testing
jsTest.log("Testing \"verbose\" command line option with no args");
@@ -38,7 +11,7 @@ var expectedResult = {
}
}
};
-testGetCmdLineOpts({ verbose : "" }, expectedResult);
+testGetCmdLineOptsMongod({ verbose : "" }, expectedResult);
jsTest.log("Testing \"verbose\" command line option with one \"v\"");
var expectedResult = {
@@ -48,7 +21,7 @@ var expectedResult = {
}
}
};
-testGetCmdLineOpts({ verbose : "v" }, expectedResult);
+testGetCmdLineOptsMongod({ verbose : "v" }, expectedResult);
jsTest.log("Testing \"verbose\" command line option with two \"v\"s");
var expectedResult = {
@@ -58,7 +31,7 @@ var expectedResult = {
}
}
};
-testGetCmdLineOpts({ verbose : "vv" }, expectedResult);
+testGetCmdLineOptsMongod({ verbose : "vv" }, expectedResult);
jsTest.log("Testing \"v\" command line option");
var expectedResult = {
@@ -69,7 +42,7 @@ var expectedResult = {
}
};
// Currently the test converts "{ v : 1 }" to "-v" when it spawns the binary.
-testGetCmdLineOpts({ v : 1 }, expectedResult);
+testGetCmdLineOptsMongod({ v : 1 }, expectedResult);
jsTest.log("Testing \"vv\" command line option");
var expectedResult = {
@@ -80,7 +53,7 @@ var expectedResult = {
}
};
// Currently the test converts "{ v : 2 }" to "-vv" when it spawns the binary.
-testGetCmdLineOpts({ v : 2 }, expectedResult);
+testGetCmdLineOptsMongod({ v : 2 }, expectedResult);
jsTest.log("Testing \"systemLog.verbosity\" config file option");
expectedResult = {
@@ -91,7 +64,8 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ config : "jstests/libs/config_files/set_verbosity.json" }, expectedResult);
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/set_verbosity.json" },
+ expectedResult);
@@ -112,7 +86,7 @@ var expectedResult = {
}
}
};
-testGetCmdLineOpts({ logpath : logDir + "/mylog.log" }, expectedResult);
+testGetCmdLineOptsMongod({ logpath : logDir + "/mylog.log" }, expectedResult);
@@ -120,7 +94,7 @@ jsTest.log("Testing with no explicit logging setting");
expectedResult = {
"parsed" : { }
};
-testGetCmdLineOpts({}, expectedResult);
+testGetCmdLineOptsMongod({}, expectedResult);
resetDbpath(baseDir);
diff --git a/jstests/noPassthrough/network_options.js b/jstests/noPassthrough/network_options.js
index 6c192f3f68f..c3baa7b38ca 100644
--- a/jstests/noPassthrough/network_options.js
+++ b/jstests/noPassthrough/network_options.js
@@ -1,33 +1,6 @@
var baseName = "jstests_core_network_options";
-function removeOptionsAddedByFramework(getCmdLineOptsResult) {
- // Remove options that we are not interested in checking, but that get set by the test
- delete getCmdLineOptsResult.parsed.setParameter
- delete getCmdLineOptsResult.parsed.storage
- delete getCmdLineOptsResult.parsed.net.port
- delete getCmdLineOptsResult.parsed.fastsync
- delete getCmdLineOptsResult.parsed.security
- return getCmdLineOptsResult;
-}
-
-function testGetCmdLineOpts(mongoRunnerConfig, expectedResult) {
-
- // Start mongod with options
- var mongod = MongoRunner.runMongod(mongoRunnerConfig);
-
- // Get the parsed options
- var getCmdLineOptsResult = mongod.adminCommand("getCmdLineOpts");
- printjson(getCmdLineOptsResult);
-
- // Remove options added by the test framework
- getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-
- // Make sure the options are equal to what we expect
- assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);
-
- // Cleanup
- MongoRunner.stopMongod(mongod.port);
-}
+load('jstests/libs/command_line/test_parsed_options.js');
// Object Check
jsTest.log("Testing \"objcheck\" command line option");
@@ -38,7 +11,7 @@ var expectedResult = {
}
}
};
-testGetCmdLineOpts({ objcheck : "" }, expectedResult);
+testGetCmdLineOptsMongod({ objcheck : "" }, expectedResult);
jsTest.log("Testing \"noobjcheck\" command line option");
expectedResult = {
@@ -48,7 +21,7 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ noobjcheck : "" }, expectedResult);
+testGetCmdLineOptsMongod({ noobjcheck : "" }, expectedResult);
jsTest.log("Testing \"net.wireObjectCheck\" config file option");
expectedResult = {
@@ -59,7 +32,8 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ config : "jstests/libs/config_files/enable_objcheck.json" }, expectedResult);
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/enable_objcheck.json" },
+ expectedResult);
jsTest.log("Testing with no explicit network option setting");
expectedResult = {
@@ -67,7 +41,7 @@ expectedResult = {
"net" : { }
}
};
-testGetCmdLineOpts({}, expectedResult);
+testGetCmdLineOptsMongod({}, expectedResult);
@@ -82,7 +56,7 @@ var expectedResult = {
}
}
};
-testGetCmdLineOpts({ httpinterface : "" }, expectedResult);
+testGetCmdLineOptsMongod({ httpinterface : "" }, expectedResult);
jsTest.log("Testing \"nohttpinterface\" command line option");
expectedResult = {
@@ -94,7 +68,7 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ nohttpinterface : "" }, expectedResult);
+testGetCmdLineOptsMongod({ nohttpinterface : "" }, expectedResult);
jsTest.log("Testing implicit enabling of http interface with \"jsonp\" command line option");
expectedResult = {
@@ -107,7 +81,7 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ jsonp : "" }, expectedResult);
+testGetCmdLineOptsMongod({ jsonp : "" }, expectedResult);
jsTest.log("Testing implicit enabling of http interface with \"rest\" command line option");
expectedResult = {
@@ -120,7 +94,7 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ rest : "" }, expectedResult);
+testGetCmdLineOptsMongod({ rest : "" }, expectedResult);
jsTest.log("Testing \"net.http.enabled\" config file option");
expectedResult = {
@@ -133,7 +107,8 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ config : "jstests/libs/config_files/enable_httpinterface.json" }, expectedResult);
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/enable_httpinterface.json" },
+ expectedResult);
jsTest.log("Testing with no explicit network option setting");
expectedResult = {
@@ -141,7 +116,7 @@ expectedResult = {
"net" : { }
}
};
-testGetCmdLineOpts({}, expectedResult);
+testGetCmdLineOptsMongod({}, expectedResult);
@@ -157,7 +132,7 @@ if (!_isWindows()) {
}
}
};
- testGetCmdLineOpts({ nounixsocket : "" }, expectedResult);
+ testGetCmdLineOptsMongod({ nounixsocket : "" }, expectedResult);
jsTest.log("Testing \"net.wireObjectCheck\" config file option");
expectedResult = {
@@ -170,7 +145,7 @@ if (!_isWindows()) {
}
}
};
- testGetCmdLineOpts({ config : "jstests/libs/config_files/enable_unixsocket.json" },
+ testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/enable_unixsocket.json" },
expectedResult);
jsTest.log("Testing with no explicit network option setting");
@@ -179,7 +154,7 @@ if (!_isWindows()) {
"net" : { }
}
};
- testGetCmdLineOpts({}, expectedResult);
+ testGetCmdLineOptsMongod({}, expectedResult);
}
print(baseName + " succeeded.");
diff --git a/jstests/noPassthrough/profile_options.js b/jstests/noPassthrough/profile_options.js
index 0ba4a5b40c3..b0101d47283 100644
--- a/jstests/noPassthrough/profile_options.js
+++ b/jstests/noPassthrough/profile_options.js
@@ -1,33 +1,6 @@
var baseName = "jstests_core_profile_options";
-function removeOptionsAddedByFramework(getCmdLineOptsResult) {
- // Remove options that we are not interested in checking, but that get set by the test
- delete getCmdLineOptsResult.parsed.setParameter
- delete getCmdLineOptsResult.parsed.storage
- delete getCmdLineOptsResult.parsed.net
- delete getCmdLineOptsResult.parsed.fastsync
- delete getCmdLineOptsResult.parsed.security
- return getCmdLineOptsResult;
-}
-
-function testGetCmdLineOpts(mongoRunnerConfig, expectedResult) {
-
- // Start mongod with options
- var mongod = MongoRunner.runMongod(mongoRunnerConfig);
-
- // Get the parsed options
- var getCmdLineOptsResult = mongod.adminCommand("getCmdLineOpts");
- printjson(getCmdLineOptsResult);
-
- // Remove options added by the test framework
- getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-
- // Make sure the options are equal to what we expect
- assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);
-
- // Cleanup
- MongoRunner.stopMongod(mongod.port);
-}
+load('jstests/libs/command_line/test_parsed_options.js');
jsTest.log("Testing \"profile\" command line option with profiling off");
var expectedResult = {
@@ -37,7 +10,7 @@ var expectedResult = {
}
}
};
-testGetCmdLineOpts({ profile : "0" }, expectedResult);
+testGetCmdLineOptsMongod({ profile : "0" }, expectedResult);
jsTest.log("Testing \"profile\" command line option with profiling slow operations on");
var expectedResult = {
@@ -47,7 +20,7 @@ var expectedResult = {
}
}
};
-testGetCmdLineOpts({ profile : "1" }, expectedResult);
+testGetCmdLineOptsMongod({ profile : "1" }, expectedResult);
jsTest.log("Testing \"profile\" command line option with profiling all on");
var expectedResult = {
@@ -57,7 +30,7 @@ var expectedResult = {
}
}
};
-testGetCmdLineOpts({ profile : "2" }, expectedResult);
+testGetCmdLineOptsMongod({ profile : "2" }, expectedResult);
jsTest.log("Testing \"operationProfiling.mode\" config file option");
expectedResult = {
@@ -68,7 +41,8 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ config : "jstests/libs/config_files/set_profiling.json" }, expectedResult);
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/set_profiling.json" },
+ expectedResult);
diff --git a/jstests/repl/repl_options.js b/jstests/repl/repl_options.js
index 42787048eb4..1d7a858a473 100644
--- a/jstests/repl/repl_options.js
+++ b/jstests/repl/repl_options.js
@@ -1,33 +1,6 @@
var baseName = "jstests_repl_repl_options";
-function removeOptionsAddedByFramework(getCmdLineOptsResult) {
- // Remove options that we are not interested in checking, but that get set by the test
- delete getCmdLineOptsResult.parsed.setParameter
- delete getCmdLineOptsResult.parsed.storage
- delete getCmdLineOptsResult.parsed.net
- delete getCmdLineOptsResult.parsed.fastsync
- delete getCmdLineOptsResult.parsed.security
- return getCmdLineOptsResult;
-}
-
-function testGetCmdLineOpts(mongoRunnerConfig, expectedResult) {
-
- // Start mongod with options
- var mongod = MongoRunner.runMongod(mongoRunnerConfig);
-
- // Get the parsed options
- var getCmdLineOptsResult = mongod.adminCommand("getCmdLineOpts");
- printjson(getCmdLineOptsResult);
-
- // Remove options added by the test framework
- getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-
- // Make sure the options are equal to what we expect
- assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);
-
- // Cleanup
- MongoRunner.stopMongod(mongod.port);
-}
+load('jstests/libs/command_line/test_parsed_options.js');
jsTest.log("Testing \"replSet\" command line option");
var expectedResult = {
@@ -37,7 +10,7 @@ var expectedResult = {
}
}
};
-testGetCmdLineOpts({ replSet : "mycmdlinename" }, expectedResult);
+testGetCmdLineOptsMongod({ replSet : "mycmdlinename" }, expectedResult);
jsTest.log("Testing \"replication.replSetName\" config file option");
expectedResult = {
@@ -48,7 +21,8 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ config : "jstests/libs/config_files/set_replsetname.json" }, expectedResult);
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/set_replsetname.json" },
+ expectedResult);
jsTest.log("Testing override of \"replication.replSetName\" config file option with \"replSet\"");
expectedResult = {
@@ -59,9 +33,7 @@ expectedResult = {
}
}
};
-testGetCmdLineOpts({ config : "jstests/libs/config_files/set_replsetname.json",
- replSet : "mycmdlinename" }, expectedResult);
-
-
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/set_replsetname.json",
+ replSet : "mycmdlinename" }, expectedResult);
print(baseName + " succeeded.");
diff --git a/jstests/sharding/sharding_options.js b/jstests/sharding/sharding_options.js
index fc410e33d0f..d3376c9ce29 100644
--- a/jstests/sharding/sharding_options.js
+++ b/jstests/sharding/sharding_options.js
@@ -1,62 +1,7 @@
var baseName = "jstests_sharding_sharding_options";
-function removeOptionsAddedByFramework(getCmdLineOptsResult) {
- // Remove options that we are not interested in checking, but that get set by the test
- delete getCmdLineOptsResult.parsed.setParameter
- delete getCmdLineOptsResult.parsed.storage
- delete getCmdLineOptsResult.parsed.net
- delete getCmdLineOptsResult.parsed.fastsync
- delete getCmdLineOptsResult.parsed.security
- return getCmdLineOptsResult;
-}
+load('jstests/libs/command_line/test_parsed_options.js');
-function testGetCmdLineOptsMongod(mongoRunnerConfig, expectedResult) {
-
- // Start mongod with options
- var mongod = MongoRunner.runMongod(mongoRunnerConfig);
-
- // Get the parsed options
- var getCmdLineOptsResult = mongod.adminCommand("getCmdLineOpts");
- printjson(getCmdLineOptsResult);
-
- // Remove options added by the test framework
- getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-
- // Make sure the options are equal to what we expect
- assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);
-
- // Cleanup
- MongoRunner.stopMongod(mongod.port);
-}
-
-function testGetCmdLineOptsMongos(mongoRunnerConfig, expectedResult) {
-
- // Start mongod with options
- var mongod = MongoRunner.runMongod();
-
- // Add configdb option
- mongoRunnerConfig['configdb'] = mongod.host;
-
- // Start mongos connected to mongod
- var mongos = MongoRunner.runMongos(mongoRunnerConfig);
-
- // Get the parsed options
- var getCmdLineOptsResult = mongos.adminCommand("getCmdLineOpts");
- printjson(getCmdLineOptsResult);
-
- // Remove options added by the test framework
- getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
-
- // Remove the configdb option
- delete getCmdLineOptsResult.parsed.sharding.configDB;
-
- // Make sure the options are equal to what we expect
- assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);
-
- // Cleanup
- MongoRunner.stopMongod(mongod.port);
- MongoRunner.stopMongos(mongos.port);
-}
// Move Paranoia
@@ -89,7 +34,8 @@ expectedResult = {
}
}
};
-testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/enable_paranoia.json" }, expectedResult);
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/enable_paranoia.json" },
+ expectedResult);
@@ -123,7 +69,8 @@ expectedResult = {
}
}
};
-testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/set_shardingrole.json" }, expectedResult);
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/set_shardingrole.json" },
+ expectedResult);
@@ -150,6 +97,4 @@ expectedResult = {
testGetCmdLineOptsMongos({ config : "jstests/libs/config_files/enable_autosplit.json" },
expectedResult);
-
-
print(baseName + " succeeded.");