summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/logging_options.js
blob: b3d999a53a8564889e2c3e97d18d5790f237c060 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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);
}

// Verbosity testing
jsTest.log("Testing \"verbose\" command line option with no args");
var expectedResult = {
    "parsed" : {
        "systemLog" : {
            "verbosity" : 1
        }
    }
};
testGetCmdLineOpts({ verbose : "" }, expectedResult);

jsTest.log("Testing \"verbose\" command line option with one \"v\"");
var expectedResult = {
    "parsed" : {
        "systemLog" : {
            "verbosity" : 1
        }
    }
};
testGetCmdLineOpts({ verbose : "v" }, expectedResult);

jsTest.log("Testing \"verbose\" command line option with two \"v\"s");
var expectedResult = {
    "parsed" : {
        "systemLog" : {
            "verbosity" : 2
        }
    }
};
testGetCmdLineOpts({ verbose : "vv" }, expectedResult);

jsTest.log("Testing \"v\" command line option");
var expectedResult = {
    "parsed" : {
        "systemLog" : {
            "verbosity" : 1
        }
    }
};
// Currently the test converts "{ v : 1 }" to "-v" when it spawns the binary.
testGetCmdLineOpts({ v : 1 }, expectedResult);

jsTest.log("Testing \"vv\" command line option");
var expectedResult = {
    "parsed" : {
        "systemLog" : {
            "verbosity" : 2
        }
    }
};
// Currently the test converts "{ v : 2 }" to "-vv" when it spawns the binary.
testGetCmdLineOpts({ v : 2 }, expectedResult);

jsTest.log("Testing \"systemLog.verbosity\" config file option");
expectedResult = {
    "parsed" : {
        "config" : "jstests/libs/config_files/set_verbosity.json",
        "systemLog" : {
            "verbosity" : 5
        }
    }
};
testGetCmdLineOpts({ config : "jstests/libs/config_files/set_verbosity.json" }, expectedResult);



// Log output testing
var baseDir = MongoRunner.dataPath + baseName;
var logDir = MongoRunner.dataPath + baseName + "/logs/";

// ensure log directory exists
assert(mkdir(baseDir));
assert(mkdir(logDir));

jsTest.log("Testing \"logpath\" command line option");
var expectedResult = {
    "parsed" : {
        "systemLog" : {
            "destination" : "file",
            "path" : logDir + "/mylog.log"
        }
    }
};
testGetCmdLineOpts({ logpath : logDir + "/mylog.log" }, expectedResult);



jsTest.log("Testing with no explicit logging setting");
expectedResult = {
    "parsed" : { }
};
testGetCmdLineOpts({}, expectedResult);

resetDbpath(baseDir);

print(baseName + " succeeded.");