2014-05-23 20:53:50 +00:00
|
|
|
var Filer = require('../../..');
|
|
|
|
var expect = require('chai').expect;
|
2014-01-21 21:25:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
describe("Filer.FileSystem.providers.Memory", function() {
|
|
|
|
it("is supported -- if it isn't, none of these tests can run.", function() {
|
|
|
|
expect(Filer.FileSystem.providers.Memory.isSupported()).to.be.true;
|
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it("has open, getReadOnlyContext, and getReadWriteContext instance methods", function() {
|
|
|
|
var memoryProvider = new Filer.FileSystem.providers.Memory();
|
|
|
|
expect(memoryProvider.open).to.be.a('function');
|
|
|
|
expect(memoryProvider.getReadOnlyContext).to.be.a('function');
|
|
|
|
expect(memoryProvider.getReadWriteContext).to.be.a('function');
|
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
describe("open an Memory provider", function() {
|
|
|
|
it("should open a new Memory database", function(done) {
|
|
|
|
var provider = new Filer.FileSystem.providers.Memory();
|
|
|
|
provider.open(function(error, firstAccess) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(firstAccess).to.be.true;
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
describe("Read/Write operations on an Memory provider", function() {
|
|
|
|
it("should allow put() and get()", function(done) {
|
|
|
|
var provider = new Filer.FileSystem.providers.Memory();
|
|
|
|
provider.open(function(error, firstAccess) {
|
|
|
|
if(error) throw error;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
var context = provider.getReadWriteContext();
|
|
|
|
context.put("key", "value", function(error, result) {
|
|
|
|
if(error) throw error;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
context.get("key", function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).to.equal("value");
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should allow delete()", function(done) {
|
|
|
|
var provider = new Filer.FileSystem.providers.Memory();
|
|
|
|
provider.open(function(error, firstAccess) {
|
|
|
|
if(error) throw error;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
var context = provider.getReadWriteContext();
|
|
|
|
context.put("key", "value", function(error, result) {
|
2014-01-21 21:25:09 +00:00
|
|
|
if(error) throw error;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
context.delete("key", function(error, result) {
|
2014-01-21 21:25:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
context.get("key", function(error, result) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should allow clear()", function(done) {
|
|
|
|
var provider = new Filer.FileSystem.providers.Memory();
|
|
|
|
provider.open(function(error, firstAccess) {
|
|
|
|
if(error) throw error;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
var context = provider.getReadWriteContext();
|
|
|
|
context.put("key1", "value1", function(error, result) {
|
2014-01-21 21:25:09 +00:00
|
|
|
if(error) throw error;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
context.put("key2", "value2", function(error, result) {
|
2014-01-21 21:25:09 +00:00
|
|
|
if(error) throw error;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
context.clear(function(err) {
|
2014-01-21 21:25:09 +00:00
|
|
|
if(error) throw error;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
context.get("key1", function(error, result) {
|
2014-01-21 21:25:09 +00:00
|
|
|
if(error) throw error;
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(result).not.to.exist;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
context.get("key2", function(error, result) {
|
2014-01-21 21:25:09 +00:00
|
|
|
if(error) throw error;
|
|
|
|
expect(result).not.to.exist;
|
2014-05-23 20:53:50 +00:00
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it("should fail when trying to write on ReadOnlyContext", function(done) {
|
|
|
|
var provider = new Filer.FileSystem.providers.Memory();
|
|
|
|
provider.open(function(error, firstAccess) {
|
|
|
|
if(error) throw error;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
var context = provider.getReadOnlyContext();
|
|
|
|
context.put("key1", "value1", function(error, result) {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|