-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(custom-pk): conver
custom_pk
tests to mocha style
- Loading branch information
Showing
1 changed file
with
48 additions
and
37 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,41 +1,52 @@ | ||
'use strict'; | ||
var test = require('./shared').assert; | ||
var setupDatabase = require('./shared').setupDatabase; | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
exports.shouldCreateRecordsWithCustomPKFactory = { | ||
metadata: { | ||
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } | ||
}, | ||
|
||
// The actual test we wish to run | ||
test: function(configuration, test) { | ||
var ObjectID = configuration.require.ObjectID; | ||
|
||
// Custom factory (need to provide a 12 byte array); | ||
var CustomPKFactory = function() {}; | ||
CustomPKFactory.prototype = new Object(); | ||
CustomPKFactory.createPk = function() { | ||
return new ObjectID('aaaaaaaaaaaa'); | ||
}; | ||
|
||
var client = configuration.newDbInstance(configuration.writeConcernMax(), { | ||
poolSize: 1, | ||
pkFactory: CustomPKFactory | ||
}); | ||
client.connect(function(err, client) { | ||
var db = client.db(configuration.database); | ||
|
||
var collection = db.collection('test_custom_key'); | ||
|
||
collection.insert({ a: 1 }, { w: 1 }, function(err, doc) { | ||
collection.find({ _id: new ObjectID('aaaaaaaaaaaa') }).toArray(function(err, items) { | ||
test.equal(1, items.length); | ||
|
||
client.close(); | ||
test.done(); | ||
describe('Custom PK', function() { | ||
before(function() { | ||
return setupDatabase(this.configuration); | ||
}); | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
it('should create records with custom PK factory', { | ||
metadata: { | ||
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } | ||
}, | ||
|
||
// The actual test we wish to run | ||
test: function(done) { | ||
var configuration = this.configuration; | ||
var ObjectID = configuration.require.ObjectID; | ||
|
||
// Custom factory (need to provide a 12 byte array); | ||
var CustomPKFactory = function() {}; | ||
CustomPKFactory.prototype = new Object(); | ||
CustomPKFactory.createPk = function() { | ||
return new ObjectID('aaaaaaaaaaaa'); | ||
}; | ||
|
||
var client = configuration.newClient({ | ||
w: 1, | ||
poolSize: 1, | ||
pkFactory: CustomPKFactory | ||
}); | ||
|
||
client.connect(function(err, client) { | ||
var db = client.db(configuration.db); | ||
var collection = db.collection('test_custom_key'); | ||
|
||
collection.insert({ a: 1 }, { w: 1 }, function(err) { | ||
test.equal(null, err); | ||
collection.find({ _id: new ObjectID('aaaaaaaaaaaa') }).toArray(function(err, items) { | ||
test.equal(1, items.length); | ||
|
||
client.close(); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
}; | ||
} | ||
}); | ||
}); |