diff options
author | Tyler Brock <tyler.brock@gmail.com> | 2014-10-06 16:19:33 -0400 |
---|---|---|
committer | Tyler Brock <tyler.brock@gmail.com> | 2014-10-07 13:11:30 -0400 |
commit | 59deabf9a55140fa502e637058983d67118e3722 (patch) | |
tree | 3640a3b5ecd335c0cc712f3afc9181479f836768 | |
parent | 2b7b105b3c26bc779d30d3c7ec4b93a0115569a8 (diff) | |
download | mongo-59deabf9a55140fa502e637058983d67118e3722.tar.gz |
SERVER-11118 add additional $dateToString aggregation tests
-rw-r--r-- | jstests/aggregation/bugs/server11118.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/jstests/aggregation/bugs/server11118.js b/jstests/aggregation/bugs/server11118.js index a2f5841292e..1ec99024a82 100644 --- a/jstests/aggregation/bugs/server11118.js +++ b/jstests/aggregation/bugs/server11118.js @@ -4,6 +4,7 @@ load('jstests/aggregation/extras/utils.js'); db = db.getSiblingDB("aggdb"); +// Used to verify expected output format function testFormat(date, formatStr, expectedStr) { db.dates.drop(); db.dates.insert({date: date}); @@ -21,6 +22,7 @@ function testFormat(date, formatStr, expectedStr) { assert.eq(res[0].formatted, expectedStr); } +// Used to verify that server recognizes bad formats function testFormatError(formatObj, errCode) { db.dates.drop(); db.dates.insert({tm: ISODate()}); @@ -32,6 +34,16 @@ function testFormatError(formatObj, errCode) { }}}, errCode); } +// Used to verify that only date values are accepted for date parameter +function testDateValueError(dateVal, errCode) { + db.dates.drop(); + db.dates.insert({date: dateVal}); + + assertErrorCode(db.dates, { $project: + { formatted: { $dateToString : { format: "%Y", date: "$date" }} } + }, errCode); +} + var now = ISODate(); // Use all modifiers we can test with js provided function @@ -104,3 +116,55 @@ testFormatError({format: "AAAAA%%%AAAAAA", date:"$date"}, 18536); // Format parameter not a string testFormatError({format: {iamalion: "roar"}, date:"$date"}, 18533); + +/// +/// Additional Tests +/// + +// Test document +var date = ISODate("1999-08-29"); + +testFormat(date, "%%d", "%d"); + +//A very long string of "%"s +var longstr = Array(1000).join("%%"); +var halfstr = Array(1000).join("%"); +testFormat(date, longstr, halfstr); + +// Using subexpressions as format strings (eg "format: '$b'") +testFormat(date, "$b", "$b"); + +// Dates as null (should return a null) +testFormat(null, "%Y", null); + +/// +/// Using non-date fields as date parameter *should fail* +/// + +// Array +testDateValueError([], 16006); +testDateValueError([1, 2, 3], 16006); + +// Sub-object +testDateValueError({}, 16006); +testDateValueError({a: 1}, 16006); + +// String +testDateValueError("blahblahblah", 16006); + +// Integer +testDateValueError(1234, 16006); + +/// +/// Using non-string fields as format strings +/// + +// Array +testFormatError({format: [], date: "$date"}, 18533); +testFormatError({format: [1, 2, 3], date: "$date"}, 18533); + +// Integer +testFormatError({format: 1, date: "$date"}, 18533); + +// Date +testFormatError({format: ISODate(), date: "$date"}, 18533); |