2018-07-26 21:50:32 +00:00
|
|
|
/* eslint no-console: 0 */
|
|
|
|
|
2018-06-28 23:26:08 +00:00
|
|
|
var Buffer = require('../../../src').Buffer;
|
2014-08-16 20:22:41 +00:00
|
|
|
var util = require('../../lib/test-utils.js');
|
|
|
|
var expect = require('chai').expect;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Due to the different setup/cleanup needs of the built-in providers,
|
|
|
|
* we use the test provider wrappers instead of the raw providers themselves.
|
|
|
|
*/
|
|
|
|
module.exports = function createProviderTestsFor(providerName, testProvider) {
|
|
|
|
if(!testProvider.isSupported()) {
|
2018-07-15 17:25:35 +00:00
|
|
|
console.log('Skipping provider tests for `' + providerName +'\'--not supported in current environment.');
|
2014-08-16 20:22:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
describe('Filer Provider Tests for ' + providerName, function() {
|
2014-08-16 20:22:41 +00:00
|
|
|
var _provider;
|
|
|
|
var provider;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
_provider = new testProvider(util.uniqueName());
|
|
|
|
_provider.init();
|
|
|
|
provider = _provider.provider;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function(done) {
|
|
|
|
_provider.cleanup(done);
|
|
|
|
_provider = null;
|
|
|
|
provider = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
it('has open, getReadOnlyContext, and getReadWriteContext instance methods', function() {
|
2014-08-16 20:22:41 +00:00
|
|
|
expect(provider.open).to.be.a('function');
|
|
|
|
expect(provider.getReadOnlyContext).to.be.a('function');
|
|
|
|
expect(provider.getReadWriteContext).to.be.a('function');
|
|
|
|
});
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
it('should open a new provider database', function(done) {
|
2014-08-21 00:53:01 +00:00
|
|
|
provider.open(function(error) {
|
2014-08-16 20:22:41 +00:00
|
|
|
expect(error).not.to.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
it('should allow putObject() and getObject()', function(done) {
|
2018-07-26 21:50:32 +00:00
|
|
|
provider.open(function(error) {
|
2014-08-16 20:22:41 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
var context = provider.getReadWriteContext();
|
|
|
|
// Simple JS Object
|
|
|
|
var value = {
|
2018-07-15 17:25:35 +00:00
|
|
|
a: 'a',
|
2014-08-16 20:22:41 +00:00
|
|
|
b: 1,
|
|
|
|
c: true,
|
|
|
|
d: [1,2,3],
|
|
|
|
e: {
|
|
|
|
e1: ['a', 'b', 'c']
|
|
|
|
}
|
|
|
|
};
|
2018-07-15 17:25:35 +00:00
|
|
|
context.putObject('key', value, function(error) {
|
2014-08-16 20:22:41 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
context.getObject('key', function(error, result) {
|
2014-08-16 20:22:41 +00:00
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).to.be.an('object');
|
|
|
|
expect(result).to.deep.equal(value);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
it('should allow putBuffer() and getBuffer()', function(done) {
|
2018-07-26 21:50:32 +00:00
|
|
|
provider.open(function(error) {
|
2014-08-16 20:22:41 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
var context = provider.getReadWriteContext();
|
|
|
|
// Filer Buffer
|
|
|
|
var buf = new Buffer([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
2018-07-15 17:25:35 +00:00
|
|
|
context.putBuffer('key', buf, function(error) {
|
2014-08-16 20:22:41 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
context.getBuffer('key', function(error, result) {
|
2014-08-16 20:22:41 +00:00
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(Buffer.isBuffer(result)).to.be.true;
|
|
|
|
expect(result).to.deep.equal(buf);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
it('should allow zero-length Buffers with putBuffer() and getBuffer()', function(done) {
|
2018-07-26 21:50:32 +00:00
|
|
|
provider.open(function(error) {
|
2014-08-16 21:07:38 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
var context = provider.getReadWriteContext();
|
|
|
|
// Zero-length Filer Buffer
|
|
|
|
var buf = new Buffer(new ArrayBuffer(0));
|
2018-07-15 17:25:35 +00:00
|
|
|
context.putBuffer('key', buf, function(error) {
|
2014-08-16 21:07:38 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
context.getBuffer('key', function(error, result) {
|
2014-08-16 21:07:38 +00:00
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(Buffer.isBuffer(result)).to.be.true;
|
|
|
|
expect(result).to.deep.equal(buf);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
it('should allow delete()', function(done) {
|
2014-08-16 20:22:41 +00:00
|
|
|
var provider = _provider.provider;
|
2018-07-26 21:50:32 +00:00
|
|
|
provider.open(function(error) {
|
2014-08-16 20:22:41 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
var context = provider.getReadWriteContext();
|
2018-07-15 17:25:35 +00:00
|
|
|
context.putObject('key', 'value', function(error) {
|
2014-08-16 20:22:41 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
context.delete('key', function(error) {
|
2014-08-16 20:22:41 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
context.getObject('key', function(error, result) {
|
2014-08-16 20:22:41 +00:00
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
it('should allow clear()', function(done) {
|
2018-07-26 21:50:32 +00:00
|
|
|
provider.open(function(error) {
|
2014-08-16 20:22:41 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
|
|
|
var context = provider.getReadWriteContext();
|
2018-07-15 17:25:35 +00:00
|
|
|
context.putObject('key1', 'value1', function(error) {
|
2014-08-16 20:22:41 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
context.putObject('key2', 'value2', function(error) {
|
2014-08-16 20:22:41 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2018-07-26 21:50:32 +00:00
|
|
|
context.clear(function(error) {
|
2014-08-16 20:22:41 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
context.getObject('key1', function(error, result) {
|
2014-08-16 20:22:41 +00:00
|
|
|
if(error) throw error;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
|
2018-07-15 17:25:35 +00:00
|
|
|
context.getObject('key2', function(error, result) {
|
2014-08-16 20:22:41 +00:00
|
|
|
if(error) throw error;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|