diff options
Diffstat (limited to 'jstests/multiVersion/libs/verify_collection_data.js')
-rw-r--r-- | jstests/multiVersion/libs/verify_collection_data.js | 78 |
1 files changed, 44 insertions, 34 deletions
diff --git a/jstests/multiVersion/libs/verify_collection_data.js b/jstests/multiVersion/libs/verify_collection_data.js index 73e54f32f48..1b0437917ee 100644 --- a/jstests/multiVersion/libs/verify_collection_data.js +++ b/jstests/multiVersion/libs/verify_collection_data.js @@ -18,10 +18,10 @@ // 4. Do round trip or other testing // 5. Validate that collection has not changed using the CollectionDataValidator class -load( './jstests/multiVersion/libs/data_generators.js' ); +load('./jstests/multiVersion/libs/data_generators.js'); // Function to actually add the data generated by the given dataGenerator to a collection -createCollectionWithData = function (db, collectionName, dataGenerator) { +createCollectionWithData = function(db, collectionName, dataGenerator) { // Drop collection if exists // TODO: add ability to control this @@ -67,7 +67,6 @@ createCollectionWithData = function (db, collectionName, dataGenerator) { // Class to save the state of a collection and later compare the current state of a collection to // the saved state function CollectionDataValidator() { - var _initialized = false; var _collectionInfo = {}; var _indexData = []; @@ -81,25 +80,27 @@ function CollectionDataValidator() { }; // Saves the current state of the collection passed in - this.recordCollectionData = function (collection) { + this.recordCollectionData = function(collection) { // Save the metadata for this collection for later comparison. _collectionInfo = this.getCollectionInfo(collection); // Save the indexes for this collection for later comparison - _indexData = collection.getIndexes().sort(function(a,b) { - if (a.name > b.name) return 1; - else return -1; + _indexData = collection.getIndexes().sort(function(a, b) { + if (a.name > b.name) + return 1; + else + return -1; }); // Save the data for this collection for later comparison - _collectionData = collection.find().sort({"_id":1}).toArray(); + _collectionData = collection.find().sort({"_id": 1}).toArray(); _initialized = true; return collection; }; - this.validateCollectionData = function (collection) { + this.validateCollectionData = function(collection) { if (!_initialized) { throw Error("validateCollectionWithAllData called, but data is not initialized"); @@ -111,16 +112,18 @@ function CollectionDataValidator() { assert.docEq(_collectionInfo, newCollectionInfo, "collection metadata not equal"); // Get the indexes for this collection - var newIndexData = collection.getIndexes().sort(function(a,b) { - if (a.name > b.name) return 1; - else return -1; + var newIndexData = collection.getIndexes().sort(function(a, b) { + if (a.name > b.name) + return 1; + else + return -1; }); for (var i = 0; i < newIndexData.length; i++) { assert.docEq(_indexData[i], newIndexData[i], "indexes not equal"); } // Save the data for this collection for later comparison - var newCollectionData = collection.find().sort({"_id":1}).toArray(); + var newCollectionData = collection.find().sort({"_id": 1}).toArray(); for (var i = 0; i < newCollectionData.length; i++) { assert.docEq(_collectionData[i], newCollectionData[i], "data not equal"); } @@ -130,52 +133,59 @@ function CollectionDataValidator() { // Tests of the functions and classes in this file function collectionDataValidatorTests() { - // TODO: These tests are hackish and depend on implementation details, but they are good enough // for now to convince us that the CollectionDataValidator is actually checking something var myValidator; var myGenerator; var collection; - myGenerator = new CollectionDataGenerator({ "capped" : true }); + myGenerator = new CollectionDataGenerator({"capped": true}); collection = createCollectionWithData(db, "test", myGenerator); myValidator = new CollectionDataValidator(); myValidator.recordCollectionData(collection); - db.test.dropIndex(db.test.getIndexKeys().filter(function(key) { return key.a != null; })[0]); - assert.throws(myValidator.validateCollectionData, [collection], "Validation function should have thrown since we modified the collection"); - - - myGenerator = new CollectionDataGenerator({ "capped" : true }); + db.test.dropIndex(db.test.getIndexKeys().filter(function(key) { + return key.a != null; + })[0]); + assert.throws(myValidator.validateCollectionData, + [collection], + "Validation function should have thrown since we modified the collection"); + + myGenerator = new CollectionDataGenerator({"capped": true}); collection = createCollectionWithData(db, "test", myGenerator); myValidator = new CollectionDataValidator(); myValidator.recordCollectionData(collection); - db.test.update({_id:0}, {dummy:1}); - assert.throws(myValidator.validateCollectionData, [collection], "Validation function should have thrown since we modified the collection"); + db.test.update({_id: 0}, {dummy: 1}); + assert.throws(myValidator.validateCollectionData, + [collection], + "Validation function should have thrown since we modified the collection"); - - myGenerator = new CollectionDataGenerator({ "capped" : true }); + myGenerator = new CollectionDataGenerator({"capped": true}); collection = createCollectionWithData(db, "test", myGenerator); myValidator = new CollectionDataValidator(); myValidator.recordCollectionData(collection); assert(myValidator.validateCollectionData(collection), "Validation function failed"); - myGenerator = new CollectionDataGenerator({ "capped" : false }); + myGenerator = new CollectionDataGenerator({"capped": false}); collection = createCollectionWithData(db, "test", myGenerator); myValidator = new CollectionDataValidator(); myValidator.recordCollectionData(collection); - db.test.dropIndex(db.test.getIndexKeys().filter(function(key) { return key.a != null; })[0]); - assert.throws(myValidator.validateCollectionData, [collection], "Validation function should have thrown since we modified the collection"); - - - myGenerator = new CollectionDataGenerator({ "capped" : false }); + db.test.dropIndex(db.test.getIndexKeys().filter(function(key) { + return key.a != null; + })[0]); + assert.throws(myValidator.validateCollectionData, + [collection], + "Validation function should have thrown since we modified the collection"); + + myGenerator = new CollectionDataGenerator({"capped": false}); collection = createCollectionWithData(db, "test", myGenerator); myValidator = new CollectionDataValidator(); myValidator.recordCollectionData(collection); - db.test.update({_id:0}, {dummy:1}); - assert.throws(myValidator.validateCollectionData, [collection], "Validation function should have thrown since we modified the collection"); - + db.test.update({_id: 0}, {dummy: 1}); + assert.throws(myValidator.validateCollectionData, + [collection], + "Validation function should have thrown since we modified the collection"); - myGenerator = new CollectionDataGenerator({ "capped" : false }); + myGenerator = new CollectionDataGenerator({"capped": false}); collection = createCollectionWithData(db, "test", myGenerator); myValidator = new CollectionDataValidator(); myValidator.recordCollectionData(collection); |