slouch/test/utils.js
Jeffrey Layanto 0e2e5e7325
The rest of partitioned database support (#131)
Co-authored-by: Jeffrey Layanto <jeffrey@layanto.com>
2020-08-22 07:44:46 -07:00

42 lines
1.1 KiB
JavaScript

'use strict';
var config = require('./config.json'),
Slouch = require('../scripts');
var Utils = function () {
this._dbId = 0;
this.createdDB = null;
this._slouch = new Slouch(this.couchDBURL());
};
Utils.prototype.couchDBURL = function () {
return config.couchdb.scheme + '://' + config.couchdb.username + ':' +
config.couchdb.password + '@' + config.couchdb.host + ':' + config.couchdb.port;
};
Utils.prototype.couchDBURLNoAuth = function () {
return config.couchdb.scheme + '://' + config.couchdb.host + ':' + config.couchdb.port;
};
Utils.prototype.nextId = function () {
return this._dbId++;
};
// Use unique DB names for each tests as there can be race conditions where a DB is destroyed, but
// has not yet been fully released.
Utils.prototype.createDB = function (partitioned) {
this.createdDB = 'test$()+-/_' + this.nextId();
if (partitioned) {
return this._slouch.db.create(this.createdDB, {
partitioned: true
});
} else {
return this._slouch.db.create(this.createdDB);
}
};
Utils.prototype.destroyDB = function () {
return this._slouch.db.destroy(this.createdDB);
};
module.exports = new Utils();