Browse files

Refactoring for pulling out the bson code into seperate npm package

  • Loading branch information...
1 parent 47d9e29 commit dd7a809a52b691ad1a56c201b45035e6495e7784 @christkv committed Mar 11, 2012
Showing with 261 additions and 376 deletions.
  1. +3 −3 lib/mongodb/gridfs/gridstore.js
  2. +56 −93 lib/mongodb/index.js
  3. +0 −1 package.json
  4. +1 −1 test/admin_test.js
  5. +1 −1 test/aggregation_framework_test.js
  6. +1 −1 test/authentication_test.js
  7. +0 −215 test/bson_types_test.js
  8. +1 −1 test/collection_test.js
  9. +128 −0 test/commands_test.js
  10. +1 −1 test/connect_test.js
  11. +1 −1 test/connection/connection_pool_test.js
  12. +2 −3 test/connection_test.js
  13. +1 −1 test/cursor_test.js
  14. +1 −1 test/cursorstream_test.js
  15. +1 −1 test/custom_pk_test.js
  16. +1 −1 test/db_test.js
  17. +1 −1 test/error_test.js
  18. +1 −1 test/exception_handling_test.js
  19. +1 −1 test/find_test.js
  20. +1 −1 test/geo_search_test.js
  21. +6 −4 test/gridstore/grid_store_file_test.js
  22. +1 −1 test/gridstore/grid_store_stream_test.js
  23. +1 −1 test/gridstore/grid_store_test.js
  24. +1 −1 test/gridstore/grid_test.js
  25. +1 −1 test/gridstore/readstream_test.js
  26. +1 −1 test/index_test.js
  27. +1 −1 test/insert_test.js
  28. +1 −1 test/logging_test.js
  29. +1 −1 test/map_reduce_test.js
  30. +1 −1 test/multiple_dbs_on_connection_pool_test.js
  31. +1 −1 test/objectid_test.js
  32. +1 −1 test/raw_test.js
  33. +1 −1 test/reaper_test.js
  34. +1 −1 test/regexp_test.js
  35. +1 −1 test/remove_test.js
  36. +4 −3 test/replicaset/connect_test.js
  37. +4 −3 test/replicaset/count_test.js
  38. +4 −3 test/replicaset/insert_test.js
  39. +4 −3 test/replicaset/map_reduce_test.js
  40. +4 −3 test/replicaset/query_secondaries_test.js
  41. +4 −3 test/replicaset/read_preference_replicaset_test.js
  42. +4 −3 test/replicaset/read_preferences_single_test.js
  43. +4 −3 test/replicaset/tags_test.js
  44. +4 −3 test/replicaset/two_server_tests.js
  45. +1 −1 test/streaming_test.js
  46. +1 −1 test/unicode_test.js
View
6 lib/mongodb/gridfs/gridstore.js
@@ -316,11 +316,11 @@ GridStore.prototype.write = function(data, close, callback) {
if(self.mode[0] != "w") {
callback(new Error((self.referenceBy == REFERENCE_BY_ID ? self.toHexString() : self.filename) + " not opened for writing"), null);
} else {
- if((self.currentChunk.position + data.length) > self.chunkSize) {
+ if((self.currentChunk.position + data.length) > self.chunkSize) {
var previousChunkNumber = self.currentChunk.chunkNumber;
var leftOverDataSize = self.chunkSize - self.currentChunk.position;
- var previousChunkData = data.substr(0, leftOverDataSize);
- var leftOverData = data.substr(leftOverDataSize, (data.length - leftOverDataSize));
+ var previousChunkData = data.slice(0, leftOverDataSize);
+ var leftOverData = data.slice(leftOverDataSize, (data.length - leftOverDataSize));
// Save out current Chunk as another variable and assign a new Chunk for overflow data
var saveChunk = self.currentChunk;
// Create a new chunk at once (avoid wrong writing of chunks)
View
149 lib/mongodb/index.js
@@ -1,8 +1,5 @@
-
try {
- // require('bson') = require('./bson/bson');
- // exports.BSONNative = require('../../external-libs/bson');
- require('bson') = require('bson').BSONPure;
+ exports.BSONPure = require('bson').BSONPure;
exports.BSONNative = require('bson').BSONNative;
} catch(err) {
// do nothing
@@ -42,97 +39,12 @@ try {
exports.MaxKey = require('bson').MaxKey;
exports.ObjectID = require('bson').ObjectID;
exports.Symbol = require('bson').Symbol;
- exports.Timestamp = require('bson').Timestamp;
+ exports.Timestamp = require('bson').Timestamp;
+
+ // Add BSON Parser
+ exports.BSON = require('bson').BSONPure.BSON;
});
-// // Exports all the classes for the NATIVE JS BSON Parser
-// exports.native = function() {
-// var classes = {};
-// // Map all the classes
-// [ 'bson/binary_parser'
-// , 'bson/binary'
-// , 'bson/code'
-// , 'bson/db_ref'
-// , 'bson/double'
-// , 'bson/max_key'
-// , 'bson/min_key'
-// , 'bson/ObjectID'
-// , 'bson/symbol'
-// , 'bson/timestamp'
-// , 'bson/long'
-// , '../../external-libs/bson/bson'
-// , 'commands/base_command'
-// , 'commands/db_command'
-// , 'commands/delete_command'
-// , 'commands/get_more_command'
-// , 'commands/insert_command'
-// , 'commands/kill_cursor_command'
-// , 'commands/query_command'
-// , 'commands/update_command'
-// , 'responses/mongo_reply'
-// , 'admin'
-// , 'collection'
-// , 'connection/connection'
-// , 'connection/server'
-// , 'connection/repl_set_servers'
-// , 'cursor'
-// , 'db'
-// , 'gridfs/grid'
-// , 'gridfs/chunk'
-// , 'gridfs/gridstore'].forEach(function (path) {
-// var module = require('./' + path);
-// for (var i in module) {
-// classes[i] = module[i];
-// }
-// });
-// // Return classes list
-// return classes;
-// }
-//
-// // Exports all the classes for the PURE JS BSON Parser
-// exports.pure = function() {
-// var classes = {};
-// // Map all the classes
-// [ 'bson/binary_parser'
-// , 'bson/binary'
-// , 'bson/code'
-// , 'bson/db_ref'
-// , 'bson/double'
-// , 'bson/max_key'
-// , 'bson/min_key'
-// , 'bson/ObjectID'
-// , 'bson/symbol'
-// , 'bson/timestamp'
-// , 'bson/long'
-// , './bson/bson'
-// , 'commands/base_command'
-// , 'commands/db_command'
-// , 'commands/delete_command'
-// , 'commands/get_more_command'
-// , 'commands/insert_command'
-// , 'commands/kill_cursor_command'
-// , 'commands/query_command'
-// , 'commands/update_command'
-// , 'responses/mongo_reply'
-// , 'admin'
-// , 'collection'
-// , 'connection/connection'
-// , 'connection/server'
-// , 'connection/repl_set_servers'
-// , 'cursor'
-// , 'db'
-// , 'gridfs/grid'
-// , 'gridfs/chunk'
-// , 'gridfs/gridstore'].forEach(function (path) {
-// var module = require('./' + path);
-// for (var i in module) {
-// classes[i] = module[i];
-// }
-// });
-// // Return classes list
-// return classes;
-// }
-
// Exports all the classes for the PURE JS BSON Parser
exports.pure = function() {
var classes = {};
@@ -174,6 +86,57 @@ exports.pure = function() {
classes.Symbol = require('bson').Symbol;
classes.Timestamp = require('bson').Timestamp;
+ // Add BSON Parser
+ classes.BSON = require('bson').BSONPure.BSON;
+
+ // Return classes list
+ return classes;
+}
+
+// Exports all the classes for the PURE JS BSON Parser
+exports.native = function() {
+ var classes = {};
+ // Map all the classes
+ [ 'commands/base_command'
+ , 'commands/db_command'
+ , 'commands/delete_command'
+ , 'commands/get_more_command'
+ , 'commands/insert_command'
+ , 'commands/kill_cursor_command'
+ , 'commands/query_command'
+ , 'commands/update_command'
+ , 'responses/mongo_reply'
+ , 'admin'
+ , 'collection'
+ , 'connection/connection'
+ , 'connection/server'
+ , 'connection/repl_set_servers'
+ , 'cursor'
+ , 'db'
+ , 'gridfs/grid'
+ , 'gridfs/chunk'
+ , 'gridfs/gridstore'].forEach(function (path) {
+ var module = require('./' + path);
+ for (var i in module) {
+ classes[i] = module[i];
+ }
+ });
+
+ // Add BSON Classes
+ classes.Binary = require('bson').Binary;
+ classes.Code = require('bson').Code;
+ classes.DBRef = require('bson').DBRef;
+ classes.Double = require('bson').Double;
+ classes.Long = require('bson').Long;
+ classes.MinKey = require('bson').MinKey;
+ classes.MaxKey = require('bson').MaxKey;
+ classes.ObjectID = require('bson').ObjectID;
+ classes.Symbol = require('bson').Symbol;
+ classes.Timestamp = require('bson').Timestamp;
+
+ // Add BSON Parser
+ classes.BSON = require('bson').BSONNative.BSON;
+
// Return classes list
return classes;
}
View
1 package.json
@@ -77,7 +77,6 @@
, "main": "./lib/mongodb/index"
, "directories" : { "lib" : "./lib/mongodb" }
, "engines" : { "node" : ">=0.4.0" }
-, "scripts": { "install" : "node install.js" }
, "licenses" : [ { "type" : "Apache License, Version 2.0"
, "url" : "http://www.apache.org/licenses/LICENSE-2.0" } ]
}
View
2 test/admin_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var native_parser = (process.env['TEST_NATIVE'] != null);
View
2 test/aggregation_framework_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var native_parser = (process.env['TEST_NATIVE'] != null);
View
2 test/authentication_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
215 test/bson_types_test.js
@@ -1,215 +0,0 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
-
-var testCase = require('nodeunit').testCase,
- Buffer = require('buffer').Buffer,
- gleak = require('../dev/tools/gleak'),
- fs = require('fs'),
- BSON = mongodb.BSON,
- Code = mongodb.Code,
- Binary = mongodb.Binary,
- Timestamp = mongodb.Timestamp,
- Long = mongodb.Long,
- MongoReply = mongodb.MongoReply,
- ObjectID = mongodb.ObjectID,
- Symbol = mongodb.Symbol,
- DBRef = mongodb.DBRef,
- Double = mongodb.Double,
- MinKey = mongodb.MinKey,
- MaxKey = mongodb.MaxKey,
- BinaryParser = mongodb.BinaryParser;
-
-var BSONSE = mongodb,
- BSONDE = mongodb;
-
-// for tests
-BSONDE.BSON_BINARY_SUBTYPE_DEFAULT = 0;
-BSONDE.BSON_BINARY_SUBTYPE_FUNCTION = 1;
-BSONDE.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
-BSONDE.BSON_BINARY_SUBTYPE_UUID = 3;
-BSONDE.BSON_BINARY_SUBTYPE_MD5 = 4;
-BSONDE.BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
-
-BSONSE.BSON_BINARY_SUBTYPE_DEFAULT = 0;
-BSONSE.BSON_BINARY_SUBTYPE_FUNCTION = 1;
-BSONSE.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
-BSONSE.BSON_BINARY_SUBTYPE_UUID = 3;
-BSONSE.BSON_BINARY_SUBTYPE_MD5 = 4;
-BSONSE.BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
-
-var hexStringToBinary = function(string) {
- var numberofValues = string.length / 2;
- var array = "";
-
- for(var i = 0; i < numberofValues; i++) {
- array += String.fromCharCode(parseInt(string[i*2] + string[i*2 + 1], 16));
- }
- return array;
-}
-
-var assertBuffersEqual = function(test, buffer1, buffer2) {
- if(buffer1.length != buffer2.length) test.fail("Buffers do not have the same length", buffer1, buffer2);
-
- for(var i = 0; i < buffer1.length; i++) {
- test.equal(buffer1[i], buffer2[i]);
- }
-}
-
-/**
- * Module for parsing an ISO 8601 formatted string into a Date object.
- */
-var ISODate = function (string) {
- var match;
-
- if (typeof string.getTime === "function")
- return string;
- else if (match = string.match(/^(\d{4})(-(\d{2})(-(\d{2})(T(\d{2}):(\d{2})(:(\d{2})(\.(\d+))?)?(Z|((\+|-)(\d{2}):(\d{2}))))?)?)?$/)) {
- var date = new Date();
- date.setUTCFullYear(Number(match[1]));
- date.setUTCMonth(Number(match[3]) - 1 || 0);
- date.setUTCDate(Number(match[5]) || 0);
- date.setUTCHours(Number(match[7]) || 0);
- date.setUTCMinutes(Number(match[8]) || 0);
- date.setUTCSeconds(Number(match[10]) || 0);
- date.setUTCMilliseconds(Number("." + match[12]) * 1000 || 0);
-
- if (match[13] && match[13] !== "Z") {
- var h = Number(match[16]) || 0,
- m = Number(match[17]) || 0;
-
- h *= 3600000;
- m *= 60000;
-
- var offset = h + m;
- if (match[15] == "+")
- offset = -offset;
-
- date = new Date(date.valueOf() + offset);
- }
-
- return date;
- } else
- throw new Error("Invalid ISO 8601 date given.", __filename);
-};
-
-/**
- * Retrieve the server information for the current
- * instance of the db client
- *
- * @ignore
- */
-exports.setUp = function(callback) {
- callback();
-}
-
-/**
- * Retrieve the server information for the current
- * instance of the db client
- *
- * @ignore
- */
-exports.tearDown = function(callback) {
- callback();
-}
-
-/**
- * A simple example showing the usage of the binary put method.
- *
- * @_class binary
- * @_function put
- * @ignore
- */
-exports.shouldCorrectUsePutForBinaryType = function(test) {
- // Create an empty Binary object
- var binary = new Binary(new Buffer(''), BSON.BSON_BINARY_SUBTYPE_DEFAULT);
- // Write some character to the Binary value
- binary.put('h');
- binary.put('e');
- binary.put('l');
- binary.put('l');
- binary.put('o');
- // Validate the content of the binary
- test.equal('hello', binary.toString('ascii'));
- test.done();
-}
-
-/**
- * A simple example showing the usage of the binary write method.
- *
- * @_class binary
- * @_function write
- * @ignore
- */
-exports.shouldCorrectUseWriteForBinaryType = function(test) {
- // Create an empty Binary object
- var binary = new Binary(new Buffer(''), BSON.BSON_BINARY_SUBTYPE_DEFAULT);
- // Write some data to the binary
- binary.write('hello', 0);
- // Validate the content of the binary
- test.equal('hello', binary.toString('ascii'));
- test.done();
-}
-
-/**
- * A simple example showing the usage of the binary read method.
- *
- * @_class binary
- * @_function read
- * @ignore
- */
-exports.shouldCorrectUseReadForBinaryType = function(test) {
- // Create an empty Binary object
- var binary = new Binary(new Buffer(''), BSON.BSON_BINARY_SUBTYPE_DEFAULT);
- // Write some data to the binary
- binary.write('hello', 0);
- // Read a couple of characters from the binary
- var data = binary.read(1, 2);
- // Validate the content of the binary
- test.equal('el', data.toString('ascii'));
- test.done();
-}
-
-/**
- * A simple example showing the usage of the binary value method.
- *
- * @_class binary
- * @_function value
- * @ignore
- */
-exports.shouldCorrectUseValueForBinaryType = function(test) {
- // Create an empty Binary object
- var binary = new Binary(new Buffer(''), BSON.BSON_BINARY_SUBTYPE_DEFAULT);
- // Write some data to the binary
- binary.write('hello', 0);
- // Validate the content of the binary
- test.equal('hello', binary.value());
- test.done();
-}
-
-/**
- * A simple example showing the usage of the binary length method.
- *
- * @_class binary
- * @_function length
- * @ignore
- */
-exports.shouldCorrectUseLengthForBinaryType = function(test) {
- // Create an empty Binary object
- var binary = new Binary(new Buffer(''), BSON.BSON_BINARY_SUBTYPE_DEFAULT);
- // Write some data to the binary
- binary.write('hello');
- // Validate the content of the binary
- test.equal(5, binary.length());
- test.done();
-}
-
-/**
- * Retrieve the server information for the current
- * instance of the db client
- *
- * @ignore
- */
-exports.noGlobalsLeaked = function(test) {
- var leaks = gleak.detectNew();
- test.equal(0, leaks.length, "global var leak detected: " + leaks.join(', '));
- test.done();
-}
View
2 test/collection_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
128 test/commands_test.js
@@ -0,0 +1,128 @@
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
+
+var testCase = require('nodeunit').testCase,
+ debug = require('util').debug,
+ inspect = require('util').inspect,
+ gleak = require('../dev/tools/gleak'),
+ fs = require('fs'),
+ BSON = mongodb.BSON,
+ Code = mongodb.Code,
+ Binary = mongodb.Binary,
+ Symbol = mongodb.Symbol,
+ DBRef = mongodb.DBRef,
+ Double = mongodb.Double,
+ MinKey = mongodb.MinKey,
+ MaxKey = mongodb.MaxKey,
+ Timestamp = mongodb.Timestamp,
+ Long = mongodb.Long,
+ ObjectID = mongodb.ObjectID,
+ DBRef = mongodb.DBRef,
+ BaseCommand = mongodb.BaseCommand,
+ InsertCommand = mongodb.InsertCommand,
+ UpdateCommand = mongodb.UpdateCommand,
+ DeleteCommand = mongodb.DeleteCommand,
+ GetMoreCommand = mongodb.GetMoreCommand,
+ KillCursorCommand = mongodb.KillCursorCommand,
+ QueryCommand = mongodb.QueryCommand,
+ MongoReply = mongodb.MongoReply,
+ BinaryParser = mongodb.BinaryParser;
+
+/**
+ * Retrieve the server information for the current
+ * instance of the db client
+ *
+ * @ignore
+ */
+exports.setUp = function(callback) {
+ callback();
+}
+
+/**
+ * Retrieve the server information for the current
+ * instance of the db client
+ *
+ * @ignore
+ */
+exports.tearDown = function(callback) {
+ callback();
+}
+
+exports['Should Correctly Generate an Insert Command'] = function(test) {
+ var full_collection_name = "db.users";
+ var insert_command = new InsertCommand({bson: new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey])}, full_collection_name);
+ insert_command.add({name: 'peter pan'});
+ insert_command.add({name: 'monkey king'});
+ // assert the length of the binary
+ test.equal(81, insert_command.toBinary().length);
+ test.done();
+}
+
+exports['Should Correctly Generate an Update Command'] = function(test) {
+ var full_collection_name = "db.users";
+ var flags = UpdateCommand.DB_UPSERT;
+ var selector = {name: 'peter pan'};
+ var document = {name: 'peter pan junior'};
+ // Create the command
+ var update_command = new UpdateCommand({bson: new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey])}, full_collection_name, selector, document, flags);
+ // assert the length of the binary
+ test.equal(90, update_command.toBinary().length);
+ test.done();
+}
+
+exports['Should Correctly Generate a Delete Command'] = function(test) {
+ var full_collection_name = "db.users";
+ var selector = {name: 'peter pan'};
+ // Create the command
+ var delete_command = new DeleteCommand({bson: new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey])}, full_collection_name, selector);
+ // assert the length of the binary
+ test.equal(58, delete_command.toBinary().length);
+ test.done();
+}
+
+exports['Should Correctly Generate a Get More Command'] = function(test) {
+ var full_collection_name = "db.users";
+ var numberToReturn = 100;
+ var cursorId = Long.fromNumber(10000222);
+ // Create the command
+ var get_more_command = new GetMoreCommand({bson: new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey])}, full_collection_name, numberToReturn, cursorId);
+ // assert the length of the binary
+ test.equal(41, get_more_command.toBinary().length);
+ test.done();
+}
+
+exports['Should Correctly Generate a Kill Cursors Command'] = function(test) {
+ Array.prototype.toXml = function() {}
+ var cursorIds = [Long.fromNumber(1), Long.fromNumber(10000222)];
+ // Create the command
+ var kill_cursor_command = new KillCursorCommand({bson: new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey])}, cursorIds);
+ // assert the length of the binary
+ test.equal(40, kill_cursor_command.toBinary().length);
+ test.done();
+}
+
+exports['Should Correctly Generate a Query Command'] = function(test) {
+ var full_collection_name = "db.users";
+ var options = QueryCommand.OPTS_SLAVE;
+ var numberToSkip = 100;
+ var numberToReturn = 200;
+ var query = {name:'peter pan'};
+ var query_command = new QueryCommand({bson: new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey])}, full_collection_name, options, numberToSkip, numberToReturn, query, null);
+ // assert the length of the binary
+ test.equal(62, query_command.toBinary().length);
+ // Generate command with return field filter
+ query_command = new QueryCommand({bson: new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey])}, full_collection_name, options, numberToSkip, numberToReturn, query, { a : 1, b : 1, c : 1});
+ test.equal(88, query_command.toBinary().length);
+ test.done();
+}
+
+/**
+ * Retrieve the server information for the current
+ * instance of the db client
+ *
+ * @ignore
+ */
+exports.noGlobalsLeaked = function(test) {
+ var leaks = gleak.detectNew();
+ test.equal(0, leaks.length, "global var leak detected: " + leaks.join(', '));
+ test.done();
+}
View
2 test/connect_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/connection/connection_pool_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
View
5 test/connection_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
@@ -12,8 +12,7 @@ var testCase = require('nodeunit').testCase,
Script = require('vm'),
Collection = mongodb.Collection,
Server = mongodb.Server,
- ServerManager = require('../test/tools/server_manager').ServerManager,
- mongodb = require('mongodb');
+ ServerManager = require('../test/tools/server_manager').ServerManager;
// Test db
var MONGODB = 'integration_tests';
View
2 test/cursor_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/cursorstream_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/custom_pk_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/db_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/error_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/exception_handling_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/find_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/geo_search_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
10 test/gridstore/grid_store_file_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
@@ -401,22 +401,24 @@ exports.shouldCorrectlyAppendToFile = function(test) {
var fs_client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: false}), {native_parser: (process.env['TEST_NATIVE'] != null)});
fs_client.open(function(err, fs_client) {
fs_client.dropDatabase(function(err, done) {
+ var id = new ObjectID();
+
var gridStore = new GridStore(fs_client, "test_gs_append", "w");
gridStore.open(function(err, gridStore) {
gridStore.write("hello, world!", function(err, gridStore) {
gridStore.close(function(err, result) {
var gridStore2 = new GridStore(fs_client, "test_gs_append", "w+");
gridStore2.open(function(err, gridStore) {
- gridStore.write(" how are you?", function(err, gridStore) {
- gridStore.close(function(err, result) {
+ gridStore2.write(" how are you?", function(err, gridStore) {
+ gridStore2.close(function(err, result) {
fs_client.collection('fs.chunks', function(err, collection) {
collection.count(function(err, count) {
test.equal(1, count);
GridStore.read(fs_client, 'test_gs_append', function(err, data) {
- test.equal("hello, world! how are you?", data);
+ test.equal("hello, world! how are you?", data.toString('ascii'));
fs_client.close();
test.done();
View
2 test/gridstore/grid_store_stream_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
View
2 test/gridstore/grid_store_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
View
2 test/gridstore/grid_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
View
2 test/gridstore/readstream_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
View
2 test/index_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/insert_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/logging_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/map_reduce_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/multiple_dbs_on_connection_pool_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/objectid_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/raw_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/reaper_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/regexp_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/remove_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
7 test/replicaset/connect_test.js
@@ -1,13 +1,14 @@
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var noReplicasetStart = process.env['NO_REPLICASET_START'] != null ? true : false;
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
inspect = require('util').inspect,
gleak = require('../../dev/tools/gleak'),
ReplicaSetManager = require('../tools/replica_set_manager').ReplicaSetManager,
- Db = require('../../lib/mongodb').Db,
- ReplSetServers = require('../../lib/mongodb').ReplSetServers,
- Server = require('../../lib/mongodb').Server;
+ Db = mongodb.Db,
+ ReplSetServers = mongodb.ReplSetServers,
+ Server = mongodb.Server;
// Keep instance of ReplicaSetManager
var serversUp = false;
View
7 test/replicaset/count_test.js
@@ -1,13 +1,14 @@
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var noReplicasetStart = process.env['NO_REPLICASET_START'] != null ? true : false;
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
inspect = require('util').inspect,
gleak = require('../../dev/tools/gleak'),
ReplicaSetManager = require('../tools/replica_set_manager').ReplicaSetManager,
- Db = require('../../lib/mongodb').Db,
- ReplSetServers = require('../../lib/mongodb').ReplSetServers,
- Server = require('../../lib/mongodb').Server;
+ Db = mongodb.Db,
+ ReplSetServers = mongodb.ReplSetServers,
+ Server = mongodb.Server;
// Keep instance of ReplicaSetManager
var serversUp = false;
View
7 test/replicaset/insert_test.js
@@ -1,13 +1,14 @@
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var noReplicasetStart = process.env['NO_REPLICASET_START'] != null ? true : false;
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
inspect = require('util').inspect,
gleak = require('../../dev/tools/gleak'),
ReplicaSetManager = require('../tools/replica_set_manager').ReplicaSetManager,
- Db = require('../../lib/mongodb').Db,
- ReplSetServers = require('../../lib/mongodb').ReplSetServers,
- Server = require('../../lib/mongodb').Server,
+ Db = mongodb.Db,
+ ReplSetServers = mongodb.ReplSetServers,
+ Server = mongodb.Server,
Step = require("step");
// Keep instance of ReplicaSetManager
View
7 test/replicaset/map_reduce_test.js
@@ -1,13 +1,14 @@
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var noReplicasetStart = process.env['NO_REPLICASET_START'] != null ? true : false;
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
inspect = require('util').inspect,
gleak = require('../../dev/tools/gleak'),
ReplicaSetManager = require('../tools/replica_set_manager').ReplicaSetManager,
- Db = require('../../lib/mongodb').Db,
- ReplSetServers = require('../../lib/mongodb').ReplSetServers,
- Server = require('../../lib/mongodb').Server,
+ Db = mongodb.Db,
+ ReplSetServers = mongodb.ReplSetServers,
+ Server = mongodb.Server,
Step = require("step");
// Keep instance of ReplicaSetManager
View
7 test/replicaset/query_secondaries_test.js
@@ -1,13 +1,14 @@
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var noReplicasetStart = process.env['NO_REPLICASET_START'] != null ? true : false;
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
inspect = require('util').inspect,
gleak = require('../../dev/tools/gleak'),
ReplicaSetManager = require('../tools/replica_set_manager').ReplicaSetManager,
- Db = require('../../lib/mongodb').Db,
- ReplSetServers = require('../../lib/mongodb').ReplSetServers,
- Server = require('../../lib/mongodb').Server,
+ Db = mongodb.Db,
+ ReplSetServers = mongodb.ReplSetServers,
+ Server = mongodb.Server,
Step = require("step");
// Keep instance of ReplicaSetManager
View
7 test/replicaset/read_preference_replicaset_test.js
@@ -34,16 +34,17 @@
// | | |available. | |
// | | | | |
// +----------------------+----------------+----------------+----------------+
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var noReplicasetStart = process.env['NO_REPLICASET_START'] != null ? true : false;
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
inspect = require('util').inspect,
gleak = require('../../dev/tools/gleak'),
ReplicaSetManager = require('../tools/replica_set_manager').ReplicaSetManager,
- Db = require('../../lib/mongodb').Db,
- ReplSetServers = require('../../lib/mongodb').ReplSetServers,
- Server = require('../../lib/mongodb').Server,
+ Db = mongodb.Db,
+ ReplSetServers = mongodb.ReplSetServers,
+ Server = mongodb.Server,
Step = require("step");
// Keep instance of ReplicaSetManager
View
7 test/replicaset/read_preferences_single_test.js
@@ -34,16 +34,17 @@
// | | |available. | |
// | | | | |
// +----------------------+----------------+----------------+----------------+
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var noReplicasetStart = process.env['NO_REPLICASET_START'] != null ? true : false;
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
inspect = require('util').inspect,
gleak = require('../../dev/tools/gleak'),
ReplicaSetManager = require('../tools/replica_set_manager').ReplicaSetManager,
- Db = require('../../lib/mongodb').Db,
- ReplSetServers = require('../../lib/mongodb').ReplSetServers,
- Server = require('../../lib/mongodb').Server,
+ Db = mongodb.Db,
+ ReplSetServers = mongodb.ReplSetServers,
+ Server = mongodb.Server,
Step = require("step");
// Keep instance of ReplicaSetManager
View
7 test/replicaset/tags_test.js
@@ -1,15 +1,16 @@
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var noReplicasetStart = process.env['NO_REPLICASET_START'] != null ? true : false;
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
inspect = require('util').inspect,
gleak = require('../../dev/tools/gleak'),
ReplicaSetManager = require('../tools/replica_set_manager').ReplicaSetManager,
- Db = require('../../lib/mongodb').Db,
- ReplSetServers = require('../../lib/mongodb').ReplSetServers,
+ Db = mongodb.Db,
+ ReplSetServers = mongodb.ReplSetServers,
PingStrategy = require('../../lib/mongodb/connection/strategies/ping_strategy').PingStrategy,
StatisticsStrategy = require('../../lib/mongodb/connection/strategies/statistics_strategy').StatisticsStrategy,
- Server = require('../../lib/mongodb').Server;
+ Server = mongodb.Server;
// Keep instance of ReplicaSetManager
var serversUp = false;
View
7 test/replicaset/two_server_tests.js
@@ -1,13 +1,14 @@
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../../lib/mongodb').native() : require('../../lib/mongodb').pure();
var noReplicasetStart = process.env['NO_REPLICASET_START'] != null ? true : false;
var testCase = require('nodeunit').testCase,
debug = require('util').debug,
inspect = require('util').inspect,
gleak = require('../../dev/tools/gleak'),
ReplicaSetManager = require('../tools/replica_set_manager').ReplicaSetManager,
- Db = require('../../lib/mongodb').Db,
- ReplSetServers = require('../../lib/mongodb').ReplSetServers,
- Server = require('../../lib/mongodb').Server,
+ Db = mongodb.Db,
+ ReplSetServers = mongodb.ReplSetServers,
+ Server = mongodb.Server,
Step = require("step");
// Keep instance of ReplicaSetManager
View
2 test/streaming_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,
View
2 test/unicode_test.js
@@ -1,4 +1,4 @@
-var mongodb = process.env['TEST_NATIVE'] != null ? require('mongodb').native() : require('mongodb').pure();
+var mongodb = process.env['TEST_NATIVE'] != null ? require('../lib/mongodb').native() : require('../lib/mongodb').pure();
var useSSL = process.env['USE_SSL'] != null ? true : false;
var testCase = require('nodeunit').testCase,

0 comments on commit dd7a809

Please sign in to comment.