diff options
author | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2017-09-14 17:55:27 -0400 |
---|---|---|
committer | Nick Zolnierz <nicholas.zolnierz@mongodb.com> | 2017-09-18 17:35:58 -0400 |
commit | 7b3d369d8ed11e0c998c09d19aa37ed3e721b425 (patch) | |
tree | a85a123345235b7176ed8143a071fce6fe851201 /jstests/libs/json_schema_test_runner.js | |
parent | 29faa71a0bdf07a1c9af09cf33e2953d816de1cf (diff) | |
download | mongo-7b3d369d8ed11e0c998c09d19aa37ed3e721b425.tar.gz |
SERVER-30647: Modify the 3rd party JSON Schema test suite to only test keywords supported by MongoDB
Diffstat (limited to 'jstests/libs/json_schema_test_runner.js')
-rw-r--r-- | jstests/libs/json_schema_test_runner.js | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/jstests/libs/json_schema_test_runner.js b/jstests/libs/json_schema_test_runner.js index 82ba8c2678d..8955f188c2a 100644 --- a/jstests/libs/json_schema_test_runner.js +++ b/jstests/libs/json_schema_test_runner.js @@ -4,6 +4,8 @@ (function() { "use strict"; + load("jstests/libs/assert_schema_match.js"); + const coll = db.json_schema_test_corpus; coll.drop(); @@ -13,35 +15,36 @@ throw new Error('JSON Schema tests must be run through resmoke.py'); } - function runSchemaTest(test, schema) { + function runSchemaTest(test, schema, banFromTopLevel) { assert(test.hasOwnProperty("data"), "JSON Schema test requires 'data'"); assert(test.hasOwnProperty("valid"), "JSON Schema test requires 'valid'"); const data = test["data"]; const valid = test["valid"]; - coll.drop(); - assert.writeOK(coll.insert({schema_test_wrapper: data})); - - let actualCount; try { - actualCount = - coll.find({$jsonSchema: {properties: {schema_test_wrapper: schema}}}).itcount(); + assertSchemaMatch(coll, + {properties: {schema_test_wrapper: schema}}, + {schema_test_wrapper: data}, + valid); + + // Run against a top-level schema if the data is an object, since MongoDB only stores + // records as documents. + // (Note: JS notion of an 'object' includes arrays and null.) + if (typeof data === "object" && !Array.isArray(data) && data !== null && + banFromTopLevel !== true) { + assertSchemaMatch(coll, schema, data, valid); + } } catch (e) { - throw new Error(tojson(e) + ": Failed to parse JSON Schema " + tojson(schema) + - " and data : " + tojson(data)); + throw new Error(tojson(e) + "\n\nJSON Schema test failed for schema " + tojson(schema) + + " and data " + tojson(data)); } - - const expectedCount = valid ? 1 : 0; - assert.eq( - expectedCount, - actualCount, - "JSON Schema test failed for schema " + tojson(schema) + " and data " + tojson(data)); } const testGroupList = JSON.parse(cat(jsonFilename)); testGroupList.forEach(function(testGroup) { assert(testGroup.hasOwnProperty("schema"), "JSON Schema test requires a 'schema'"); assert(testGroup.hasOwnProperty("tests"), "JSON Schema test requires a 'tests' list"); - testGroup["tests"].forEach(test => runSchemaTest(test, testGroup["schema"])); + testGroup["tests"].forEach( + test => runSchemaTest(test, testGroup["schema"], testGroup["banFromTopLevel"])); }); }()); |