Skip to content

Commit

Permalink
test(custom-pk): conver custom_pk tests to mocha style
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Sep 1, 2017
1 parent 557720f commit cbafd1a
Showing 1 changed file with 48 additions and 37 deletions.
85 changes: 48 additions & 37 deletions test/functional/custom_pk_tests.js
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();
});
});
});
});
}
};
}
});
});

0 comments on commit cbafd1a

Please sign in to comment.