forked from mongodb/node-mongodb-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Splitting out integration tests into nodeunit tests
- Loading branch information
Showing
10 changed files
with
1,157 additions
and
984 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
var testCase = require('nodeunit').testCase, | ||
debug = require('sys').debug | ||
inspect = require('sys').inspect, | ||
nodeunit = require('nodeunit'), | ||
Db = require('../lib/mongodb').Db, | ||
Cursor = require('../lib/mongodb').Cursor, | ||
Collection = require('../lib/mongodb').Collection, | ||
Server = require('../lib/mongodb').Server; | ||
|
||
var MONGODB = 'integration_tests'; | ||
var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false})); | ||
|
||
// Define the tests, we want them to run as a nested test so we only clean up the | ||
// db connection once | ||
var tests = testCase({ | ||
setUp: function(callback) { | ||
client.open(function(err, db_p) { | ||
// Save reference to db | ||
client = db_p; | ||
// Start tests | ||
callback(); | ||
}); | ||
}, | ||
|
||
tearDown: function(callback) { | ||
numberOfTestsRun = numberOfTestsRun - 1; | ||
// Drop the database and close it | ||
if(numberOfTestsRun <= 0) { | ||
client.dropDatabase(function(err, done) { | ||
client.close(); | ||
callback(); | ||
}); | ||
} else { | ||
client.close(); | ||
callback(); | ||
} | ||
}, | ||
|
||
shouldCorrectlyExecuteToArray : function(test) { | ||
// Create a non-unique index and test inserts | ||
client.createCollection('test_array', function(err, collection) { | ||
collection.insert({'b':[1, 2, 3]}, function(err, ids) { | ||
collection.find(function(err, cursor) { | ||
cursor.toArray(function(err, documents) { | ||
test.deepEqual([1, 2, 3], documents[0].b); | ||
// Let's close the db | ||
test.done(); | ||
}); | ||
}, {}); | ||
}); | ||
}); | ||
}, | ||
|
||
shouldCorrectlyExecuteToArrayAndFailOnFurtherCursorAccess : function(test) { | ||
client.createCollection('test_to_a', function(err, collection) { | ||
test.ok(collection instanceof Collection); | ||
collection.insert({'a':1}, function(err, ids) { | ||
collection.find({}, function(err, cursor) { | ||
cursor.toArray(function(err, items) { | ||
// Should fail if called again (cursor should be closed) | ||
cursor.toArray(function(err, items) { | ||
test.ok(err instanceof Error); | ||
test.equal("Cursor is closed", err.message); | ||
|
||
// Should fail if called again (cursor should be closed) | ||
cursor.each(function(err, item) { | ||
test.ok(err instanceof Error); | ||
test.equal("Cursor is closed", err.message); | ||
// Let's close the db | ||
test.done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}, | ||
|
||
shouldCorrectlyFailToArrayDueToFinishedEachOperation : function(test) { | ||
client.createCollection('test_to_a_after_each', function(err, collection) { | ||
test.ok(collection instanceof Collection); | ||
collection.insert({'a':1}, function(err, ids) { | ||
collection.find(function(err, cursor) { | ||
cursor.each(function(err, item) { | ||
if(item == null) { | ||
cursor.toArray(function(err, items) { | ||
test.ok(err instanceof Error); | ||
test.equal("Cursor is closed", err.message); | ||
|
||
// Let's close the db | ||
test.done(); | ||
}); | ||
}; | ||
}); | ||
}); | ||
}); | ||
}); | ||
}, | ||
}) | ||
|
||
// Stupid freaking workaround due to there being no way to run setup once for each suite | ||
var numberOfTestsRun = Object.keys(tests).length; | ||
// Assign out tests | ||
module.exports = tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.