1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/**
* Test to make sure that commands that should only work when testing commands are enabled
* via the --enableTestCommands flag fail when that flag isn't provided.
*/
var testOnlyCommands = [
'configureFailPoint',
'_hashBSONElement',
'replSetTest',
'journalLatencyTest',
'godinsert',
'sleep',
'cpuload',
'captrunc',
'emptycapped'
];
var assertCmdNotFound = function(db, cmdName) {
var res = db.runCommand(cmdName);
assert.eq(0, res.ok);
assert.eq(59, res.code, 'expected CommandNotFound(59) error code for test command ' + cmdName);
};
var assertCmdFound = function(db, cmdName) {
var res = db.runCommand(cmdName);
if (!res.ok) {
assert.neq(59,
res.code,
'test command ' + cmdName + ' should either have succeeded or ' +
'failed with an error code other than CommandNotFound(59)');
}
};
jsTest.setOption('enableTestCommands', false);
var conn = MongoRunner.runMongod({});
for (i in testOnlyCommands) {
assertCmdNotFound(conn.getDB('test'), testOnlyCommands[i]);
}
MongoRunner.stopMongod(conn.port);
// Now enable the commands
jsTest.setOption('enableTestCommands', true);
var conn = MongoRunner.runMongod({});
for (i in testOnlyCommands) {
assertCmdFound(conn.getDB('test'), testOnlyCommands[i]);
}
MongoRunner.stopMongod(conn.port);
|