blob: c9836de08e3e76600aae0879262eb5c2b09529f7 (
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
|
// Tests the parsing of the timeZoneInfo parameter and file use.
(function() {
// Test that a bad file causes startup to fail.
let conn = MongoRunner.runMongod({timeZoneInfo: "jstests/libs/config_files/bad_timezone_info"});
assert.eq(conn, null, "expected launching mongod with bad timezone rules to fail");
assert.neq(-1, rawMongoProgramOutput().search(/Fatal assertion.*40475/));
// Test that a non-existent directory causes startup to fail.
conn = MongoRunner.runMongod({timeZoneInfo: "jstests/libs/config_files/missing_directory"});
assert.eq(conn, null, "expected launching mongod with bad timezone rules to fail");
// Look for either old or new error message
assert(rawMongoProgramOutput().includes("Error creating service context") ||
rawMongoProgramOutput().includes("Failed to create service context"));
// Test that startup can succeed with a good file.
conn = MongoRunner.runMongod({timeZoneInfo: "jstests/libs/config_files/good_timezone_info"});
assert.neq(conn, null, "expected launching mongod with good timezone rules to succeed");
// Test that can use file-provided timezones in an expression.
const testDB = conn.getDB("test");
const coll = testDB.parse_zone_info;
assert.commandWorked(coll.insert({x: new Date()}));
assert.doesNotThrow(
() => coll.aggregate([{$set: {x_parts: {$dateToParts: {date: "$x", timezone: "GMT"}}}}]));
assert.doesNotThrow(
() => coll.aggregate(
[{$set: {x_parts: {$dateToParts: {date: "$x", timezone: "America/Sao_Paulo"}}}}]));
// Confirm that attempt to use a non-existent timezone in an expression fails.
const err = assert.throws(
() => coll.aggregate([{$set: {x_parts: {$dateToParts: {date: "$x", timezone: "Unknown"}}}}]));
assert.eq(err.code, 40485);
MongoRunner.stopMongod(conn);
}());
|