1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Remove unnecessary context storage APIs

and rename context storage APIs
This commit is contained in:
HirokiUchikawa 2018-06-20 20:00:39 +09:00
parent dd81d947fc
commit e6411d11b1
5 changed files with 182 additions and 194 deletions

View File

@ -180,17 +180,17 @@ function createContext(id,seed) {
obj.getAsync = function(key) { obj.getAsync = function(key) {
var keyPath = parseKey(key); var keyPath = parseKey(key);
var context = getContextStorage(keyPath.storage); var context = getContextStorage(keyPath.storage);
return context.getAsync(scope, keyPath.key); return context.get(scope, keyPath.key);
}; };
obj.setAsync = function(key, value) { obj.setAsync = function(key, value) {
var keyPath = parseKey(key); var keyPath = parseKey(key);
var context = getContextStorage(keyPath.storage); var context = getContextStorage(keyPath.storage);
return context.setAsync(scope, keyPath.key, value); return context.set(scope, keyPath.key, value);
}; };
obj.keysAsync = function(storage) { obj.keysAsync = function(storage) {
var storageName = parseStorage(storage); var storageName = parseStorage(storage);
var context = getContextStorage(storageName); var context = getContextStorage(storageName);
return context.keysAsync(scope); return context.keys(scope);
}; };
return obj; return obj;
} }

View File

@ -86,7 +86,7 @@ LocalFileSystem.prototype.close = function(){
return Promise.resolve(); return Promise.resolve();
} }
LocalFileSystem.prototype.getAsync = function(scope, key) { LocalFileSystem.prototype.get = function(scope, key) {
var storagePath = getStoragePath(this.storageBaseDir ,scope); var storagePath = getStoragePath(this.storageBaseDir ,scope);
return loadFile(storagePath + ".json").then(function(data){ return loadFile(storagePath + ".json").then(function(data){
if(data){ if(data){
@ -99,7 +99,7 @@ LocalFileSystem.prototype.getAsync = function(scope, key) {
}); });
}; };
LocalFileSystem.prototype.setAsync =function(scope, key, value) { LocalFileSystem.prototype.set =function(scope, key, value) {
var storagePath = getStoragePath(this.storageBaseDir ,scope); var storagePath = getStoragePath(this.storageBaseDir ,scope);
return loadFile(storagePath + ".json").then(function(data){ return loadFile(storagePath + ".json").then(function(data){
var obj = data ? JSON.parse(data) : {} var obj = data ? JSON.parse(data) : {}
@ -113,7 +113,7 @@ LocalFileSystem.prototype.setAsync =function(scope, key, value) {
}); });
}; };
LocalFileSystem.prototype.keysAsync = function(scope){ LocalFileSystem.prototype.keys = function(scope){
var storagePath = getStoragePath(this.storageBaseDir ,scope); var storagePath = getStoragePath(this.storageBaseDir ,scope);
return loadFile(storagePath + ".json").then(function(data){ return loadFile(storagePath + ".json").then(function(data){
if(data){ if(data){

View File

@ -55,18 +55,6 @@ Memory.prototype.keys = function(scope){
} }
}; };
Memory.prototype.getAsync = function(scope, key) {
return Promise.resolve(this.get(scope, key));
};
Memory.prototype.setAsync =function(scope, key, value) {
return Promise.resolve(this.set(scope, key, value));
};
Memory.prototype.keysAsync = function(scope){
return Promise.resolve(this.keys(scope));
};
Memory.prototype.delete = function(scope){ Memory.prototype.delete = function(scope){
delete this.data[scope]; delete this.data[scope];
return Promise.resolve(); return Promise.resolve();

View File

@ -168,25 +168,25 @@ describe('context', function() {
describe('external context storage',function() { describe('external context storage',function() {
var sandbox = sinon.sandbox.create(); var sandbox = sinon.sandbox.create();
var stubGetAsync = sandbox.stub().returns(Promise.resolve()); var stubGet = sandbox.stub().returns(Promise.resolve());
var stubSetAsync = sandbox.stub().returns(Promise.resolve()); var stubSet = sandbox.stub().returns(Promise.resolve());
var stubKeysAsync = sandbox.stub().returns(Promise.resolve()); var stubKeys = sandbox.stub().returns(Promise.resolve());
var stubDelete = sandbox.stub().returns(Promise.resolve()); var stubDelete = sandbox.stub().returns(Promise.resolve());
var stubClean = sandbox.stub().returns(Promise.resolve()); var stubClean = sandbox.stub().returns(Promise.resolve());
var stubOpen = sandbox.stub().returns(Promise.resolve()); var stubOpen = sandbox.stub().returns(Promise.resolve());
var stubClose = sandbox.stub().returns(Promise.resolve()); var stubClose = sandbox.stub().returns(Promise.resolve());
var stubGetAsync2 = sandbox.stub().returns(Promise.resolve()); var stubGet2 = sandbox.stub().returns(Promise.resolve());
var stubSetAsync2 = sandbox.stub().returns(Promise.resolve()); var stubSet2 = sandbox.stub().returns(Promise.resolve());
var stubKeysAsync2 = sandbox.stub().returns(Promise.resolve()); var stubKeys2 = sandbox.stub().returns(Promise.resolve());
var stubDelete2 = sandbox.stub().returns(Promise.resolve()); var stubDelete2 = sandbox.stub().returns(Promise.resolve());
var stubClean2 = sandbox.stub().returns(Promise.resolve()); var stubClean2 = sandbox.stub().returns(Promise.resolve());
var stubOpen2 = sandbox.stub().returns(Promise.resolve()); var stubOpen2 = sandbox.stub().returns(Promise.resolve());
var stubClose2 = sandbox.stub().returns(Promise.resolve()); var stubClose2 = sandbox.stub().returns(Promise.resolve());
var testPlugin = function(config){ var testPlugin = function(config){
function Test(){} function Test(){}
Test.prototype.getAsync = stubGetAsync; Test.prototype.get = stubGet;
Test.prototype.setAsync = stubSetAsync; Test.prototype.set = stubSet;
Test.prototype.keysAsync = stubKeysAsync; Test.prototype.keys = stubKeys;
Test.prototype.delete = stubDelete; Test.prototype.delete = stubDelete;
Test.prototype.clean = stubClean; Test.prototype.clean = stubClean;
Test.prototype.open = stubOpen; Test.prototype.open = stubOpen;
@ -195,9 +195,9 @@ describe('context', function() {
}; };
var testPlugin2 = function(config){ var testPlugin2 = function(config){
function Test2(){} function Test2(){}
Test2.prototype.getAsync = stubGetAsync2; Test2.prototype.get = stubGet2;
Test2.prototype.setAsync = stubSetAsync2; Test2.prototype.set = stubSet2;
Test2.prototype.keysAsync = stubKeysAsync2; Test2.prototype.keys = stubKeys2;
Test2.prototype.delete = stubDelete2; Test2.prototype.delete = stubDelete2;
Test2.prototype.clean = stubClean2; Test2.prototype.clean = stubClean2;
Test2.prototype.open = stubOpen2; Test2.prototype.open = stubOpen2;
@ -262,14 +262,14 @@ describe('context', function() {
return Context.load().then(function(){ return Context.load().then(function(){
var context = Context.get("1","flow"); var context = Context.get("1","flow");
return Promise.all([ return Promise.all([
context.setAsync("##%&.sign","sign1").then(function(){ context.set("##%&.sign","sign1").then(function(){
return context.getAsync("##%&.sign").should.finally.equal("sign1"); return context.get("##%&.sign").should.finally.equal("sign1");
}), }),
context.setAsync("#\u3042.file2","file2").then(function(){ context.set("#\u3042.file2","file2").then(function(){
return context.getAsync("#\u3042.file2").should.finally.equal("file2"); return context.get("#\u3042.file2").should.finally.equal("file2");
}), }),
context.setAsync("#1.num","num3").then(function(){ context.set("#1.num","num3").then(function(){
return context.getAsync("#1.num").should.finally.equal("num3"); return context.get("#1.num").should.finally.equal("num3");
}) })
]); ]);
}); });
@ -279,13 +279,13 @@ describe('context', function() {
return Context.load().then(function(){ return Context.load().then(function(){
var context = Context.get("1","flow"); var context = Context.get("1","flow");
return Promise.all([ return Promise.all([
context.setAsync("#_.foo","bar"), context.set("#_.foo","bar"),
context.getAsync("#_.foo"), context.get("#_.foo"),
context.keysAsync("#_") context.keys("#_")
]).then(function(){ ]).then(function(){
stubSetAsync.called.should.be.false(); stubSet.called.should.be.false();
stubGetAsync.called.should.be.false(); stubGet.called.should.be.false();
stubKeysAsync.called.should.be.false(); stubKeys.called.should.be.false();
}); });
}); });
}); });
@ -333,13 +333,13 @@ describe('context', function() {
return Context.load().then(function(){ return Context.load().then(function(){
var context = Context.get("1","flow"); var context = Context.get("1","flow");
return Promise.all([ return Promise.all([
context.setAsync("#test.foo","test"), context.set("#test.foo","test"),
context.getAsync("#test.foo"), context.get("#test.foo"),
context.keysAsync("#test") context.keys("#test")
]).then(function(){ ]).then(function(){
stubSetAsync.calledWithExactly("1:flow","foo","test").should.be.true(); stubSet.calledWithExactly("1:flow","foo","test").should.be.true();
stubGetAsync.calledWithExactly("1:flow","foo").should.be.true(); stubGet.calledWithExactly("1:flow","foo").should.be.true();
stubKeysAsync.calledWithExactly("1:flow").should.be.true(); stubKeys.calledWithExactly("1:flow").should.be.true();
}); });
}); });
}); });
@ -348,13 +348,13 @@ describe('context', function() {
return Context.load().then(function(){ return Context.load().then(function(){
var context = Context.get("1","flow"); var context = Context.get("1","flow");
return Promise.all([ return Promise.all([
context.flow.setAsync("#test.foo","test"), context.flow.set("#test.foo","test"),
context.flow.getAsync("#test.foo"), context.flow.get("#test.foo"),
context.flow.keysAsync("#test") context.flow.keys("#test")
]).then(function(){ ]).then(function(){
stubSetAsync.calledWithExactly("flow","foo","test").should.be.true(); stubSet.calledWithExactly("flow","foo","test").should.be.true();
stubGetAsync.calledWithExactly("flow","foo").should.be.true(); stubGet.calledWithExactly("flow","foo").should.be.true();
stubKeysAsync.calledWithExactly("flow").should.be.true(); stubKeys.calledWithExactly("flow").should.be.true();
}); });
}); });
}); });
@ -363,13 +363,13 @@ describe('context', function() {
return Context.load().then(function(){ return Context.load().then(function(){
var context = Context.get("1","flow"); var context = Context.get("1","flow");
return Promise.all([ return Promise.all([
context.global.setAsync("#test.foo","test"), context.global.set("#test.foo","test"),
context.global.getAsync("#test.foo"), context.global.get("#test.foo"),
context.global.keysAsync("#test") context.global.keys("#test")
]).then(function(){ ]).then(function(){
stubSetAsync.calledWithExactly("global","foo","test").should.be.true(); stubSet.calledWithExactly("global","foo","test").should.be.true();
stubGetAsync.calledWithExactly("global","foo").should.be.true(); stubGet.calledWithExactly("global","foo").should.be.true();
stubKeysAsync.calledWithExactly("global").should.be.true(); stubKeys.calledWithExactly("global").should.be.true();
}); });
}); });
}); });
@ -378,16 +378,16 @@ describe('context', function() {
return Context.load().then(function(){ return Context.load().then(function(){
var context = Context.get("1","flow"); var context = Context.get("1","flow");
return Promise.all([ return Promise.all([
context.setAsync("#nonexist.foo","test"), context.set("#nonexist.foo","test"),
context.getAsync("#nonexist.foo"), context.get("#nonexist.foo"),
context.keysAsync("#nonexist") context.keys("#nonexist")
]).then(function(){ ]).then(function(){
stubGetAsync.called.should.be.false(); stubGet.called.should.be.false();
stubSetAsync.called.should.be.false(); stubSet.called.should.be.false();
stubKeysAsync.called.should.be.false(); stubKeys.called.should.be.false();
stubSetAsync2.calledWithExactly("1:flow","foo","test").should.be.true(); stubSet2.calledWithExactly("1:flow","foo","test").should.be.true();
stubGetAsync2.calledWithExactly("1:flow","foo").should.be.true(); stubGet2.calledWithExactly("1:flow","foo").should.be.true();
stubKeysAsync2.calledWithExactly("1:flow").should.be.true(); stubKeys2.calledWithExactly("1:flow").should.be.true();
}); });
}); });
}); });
@ -396,16 +396,16 @@ describe('context', function() {
return Context.load().then(function(){ return Context.load().then(function(){
var context = Context.get("1","flow"); var context = Context.get("1","flow");
return Promise.all([ return Promise.all([
context.setAsync("#default.foo","default"), context.set("#default.foo","default"),
context.getAsync("#default.foo"), context.get("#default.foo"),
context.keysAsync("#default") context.keys("#default")
]).then(function(){ ]).then(function(){
stubGetAsync.called.should.be.false(); stubGet.called.should.be.false();
stubSetAsync.called.should.be.false(); stubSet.called.should.be.false();
stubKeysAsync.called.should.be.false(); stubKeys.called.should.be.false();
stubSetAsync2.calledWithExactly("1:flow","foo","default").should.be.true(); stubSet2.calledWithExactly("1:flow","foo","default").should.be.true();
stubGetAsync2.calledWithExactly("1:flow","foo").should.be.true(); stubGet2.calledWithExactly("1:flow","foo").should.be.true();
stubKeysAsync2.calledWithExactly("1:flow").should.be.true(); stubKeys2.calledWithExactly("1:flow").should.be.true();
}); });
}); });
}); });
@ -414,16 +414,16 @@ describe('context', function() {
return Context.load().then(function(){ return Context.load().then(function(){
var context = Context.get("1","flow"); var context = Context.get("1","flow");
return Promise.all([ return Promise.all([
context.setAsync("#.foo","alias"), context.set("#.foo","alias"),
context.getAsync("#.foo"), context.get("#.foo"),
context.keysAsync("#") context.keys("#")
]).then(function(){ ]).then(function(){
stubGetAsync.called.should.be.false(); stubGet.called.should.be.false();
stubSetAsync.called.should.be.false(); stubSet.called.should.be.false();
stubKeysAsync.called.should.be.false(); stubKeys.called.should.be.false();
stubSetAsync2.calledWithExactly("1:flow","foo","alias").should.be.true(); stubSet2.calledWithExactly("1:flow","foo","alias").should.be.true();
stubGetAsync2.calledWithExactly("1:flow","foo").should.be.true(); stubGet2.calledWithExactly("1:flow","foo").should.be.true();
stubKeysAsync2.calledWithExactly("1:flow").should.be.true(); stubKeys2.calledWithExactly("1:flow").should.be.true();
}); });
}); });
}); });
@ -432,13 +432,13 @@ describe('context', function() {
return Context.load().then(function(){ return Context.load().then(function(){
var context = Context.get("1","flow"); var context = Context.get("1","flow");
return Promise.all([ return Promise.all([
context.setAsync("#.foo","alias"), context.set("#.foo","alias"),
context.getAsync("#.foo"), context.get("#.foo"),
context.keysAsync("#") context.keys("#")
]).then(function(){ ]).then(function(){
stubSetAsync.calledWithExactly("1:flow","foo","alias").should.be.true(); stubSet.calledWithExactly("1:flow","foo","alias").should.be.true();
stubGetAsync.calledWithExactly("1:flow","foo").should.be.true(); stubGet.calledWithExactly("1:flow","foo").should.be.true();
stubKeysAsync.calledWithExactly("1:flow").should.be.true(); stubKeys.calledWithExactly("1:flow").should.be.true();
}); });
}); });
}); });
@ -446,7 +446,7 @@ describe('context', function() {
Context.init({contextStorage:contextStorage}); Context.init({contextStorage:contextStorage});
Context.load().then(function(){ Context.load().then(function(){
var context = Context.get("1","flow"); var context = Context.get("1","flow");
context.getAsync("#nonexist.local"); context.get("#nonexist.local");
should.fail(null, null, "An error was not thrown using undefined storage for local context"); should.fail(null, null, "An error was not thrown using undefined storage for local context");
}).catch(function(err) { }).catch(function(err) {
if (err.name === "ContextError") { if (err.name === "ContextError") {
@ -460,7 +460,7 @@ describe('context', function() {
Context.init({contextStorage:contextStorage}); Context.init({contextStorage:contextStorage});
Context.load().then(function(){ Context.load().then(function(){
var context = Context.get("1","flow"); var context = Context.get("1","flow");
context.flow.setAsync("#nonexist.flow"); context.flow.set("#nonexist.flow");
should.fail(null, null, "An error was not thrown using undefined storage for flow context"); should.fail(null, null, "An error was not thrown using undefined storage for flow context");
}).catch(function(err) { }).catch(function(err) {
if (err.name === "ContextError") { if (err.name === "ContextError") {
@ -510,35 +510,35 @@ describe('context', function() {
}); });
it('should work correctly with the valid key name',function() { it('should work correctly with the valid key name',function() {
return Promise.all([ return Promise.all([
context.setAsync("#memory.azAZ09#_","valid"), context.set("#memory.azAZ09#_","valid"),
context.setAsync("#memory.a.b","ab") context.set("#memory.a.b","ab")
]).then(function(){ ]).then(function(){
context.getAsync("#memory.azAZ09#_").should.finally.equal("valid"); context.get("#memory.azAZ09#_").should.finally.equal("valid");
context.getAsync("#memory.a.b").should.finally.equal("ab"); context.get("#memory.a.b").should.finally.equal("ab");
}); });
}); });
it('should treat the key name without dot as a normal context',function() { it('should treat the key name without dot as a normal context',function() {
return context.setAsync("#memory","normal").then(function(){ return context.set("#memory","normal").then(function(){
return context.getAsync("#memory").should.finally.equal("normal"); return context.get("#memory").should.finally.equal("normal");
}); });
}); });
it('should fail when specifying invalid characters',function() { it('should fail when specifying invalid characters',function() {
(function() { (function() {
context.setAsync("#memory.a.-","invalid1"); context.set("#memory.a.-","invalid1");
}).should.throw(); }).should.throw();
(function() { (function() {
context.setAsync("#memory.'abc","invalid2"); context.set("#memory.'abc","invalid2");
}).should.throw(); }).should.throw();
}); });
it('should fail when specifying unnecesary space characters for key name',function() { it('should fail when specifying unnecesary space characters for key name',function() {
(function() { (function() {
context.setAsync("# memory.space","space1"); context.set("# memory.space","space1");
}).should.throw(); }).should.throw();
(function() { (function() {
context.setAsync("#memory .space","space2"); context.set("#memory .space","space2");
}).should.throw(); }).should.throw();
(function() { (function() {
context.setAsync("#memory. space","space3"); context.set("#memory. space","space3");
}).should.throw(); }).should.throw();
}); });
}); });

View File

@ -37,68 +37,68 @@ describe('localfilesystem',function() {
}); });
}); });
describe('#getAsync/setAsync',function() { describe('#get/set',function() {
it('should store property',function() { it('should store property',function() {
return context.getAsync("nodeX","foo").should.be.finally.undefined() return context.get("nodeX","foo").should.be.finally.undefined()
.then(function(){ .then(function(){
return context.setAsync("nodeX","foo","test"); return context.set("nodeX","foo","test");
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo").should.be.finally.equal("test"); return context.get("nodeX","foo").should.be.finally.equal("test");
}); });
}); });
it('should store property - creates parent properties',function() { it('should store property - creates parent properties',function() {
return context.setAsync("nodeX","foo.bar","test").then(function(){ return context.set("nodeX","foo.bar","test").then(function(){
return context.getAsync("nodeX","foo").should.be.finally.eql({bar:"test"}); return context.get("nodeX","foo").should.be.finally.eql({bar:"test"});
}); });
}); });
it('should delete property',function() { it('should delete property',function() {
return context.setAsync("nodeX","foo.abc.bar1","test1") return context.set("nodeX","foo.abc.bar1","test1")
.then(function(){ .then(function(){
return context.setAsync("nodeX","foo.abc.bar2","test2") return context.set("nodeX","foo.abc.bar2","test2")
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo.abc").should.be.finally.eql({bar1:"test1",bar2:"test2"}); return context.get("nodeX","foo.abc").should.be.finally.eql({bar1:"test1",bar2:"test2"});
}).then(function(){ }).then(function(){
return context.setAsync("nodeX","foo.abc.bar1",undefined).then(function(){ return context.set("nodeX","foo.abc.bar1",undefined).then(function(){
return context.getAsync("nodeX","foo.abc").should.be.finally.eql({bar2:"test2"}); return context.get("nodeX","foo.abc").should.be.finally.eql({bar2:"test2"});
}); });
}).then(function(){ }).then(function(){
return context.setAsync("nodeX","foo.abc",undefined).then(function(){ return context.set("nodeX","foo.abc",undefined).then(function(){
return context.getAsync("nodeX","foo.abc").should.be.finally.undefined(); return context.get("nodeX","foo.abc").should.be.finally.undefined();
}); });
}).then(function(){ }).then(function(){
return context.setAsync("nodeX","foo",undefined).then(function(){ return context.set("nodeX","foo",undefined).then(function(){
return context.getAsync("nodeX","foo").should.be.finally.undefined(); return context.get("nodeX","foo").should.be.finally.undefined();
}); });
}); });
}); });
it('should not shared context with other scope', function() { it('should not shared context with other scope', function() {
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(), return Promise.all([context.get("nodeX","foo").should.be.finally.undefined(),
context.getAsync("nodeY","foo").should.be.finally.undefined() context.get("nodeY","foo").should.be.finally.undefined()
]).then(function(){ ]).then(function(){
return Promise.all([context.setAsync("nodeX","foo","testX"), return Promise.all([context.set("nodeX","foo","testX"),
context.setAsync("nodeY","foo","testY")]) context.set("nodeY","foo","testY")])
}).then(function(){ }).then(function(){
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("testX"), return Promise.all([context.get("nodeX","foo").should.be.finally.equal("testX"),
context.getAsync("nodeY","foo").should.be.finally.equal("testY")]); context.get("nodeY","foo").should.be.finally.equal("testY")]);
}); });
}); });
it('should store string',function() { it('should store string',function() {
return context.getAsync("nodeX","foo").should.be.finally.undefined() return context.get("nodeX","foo").should.be.finally.undefined()
.then(function(){ .then(function(){
return context.setAsync("nodeX","foo","bar"); return context.set("nodeX","foo","bar");
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo") return context.get("nodeX","foo")
}).then(function(result){ }).then(function(result){
result.should.be.String(); result.should.be.String();
result.should.be.equal("bar"); result.should.be.equal("bar");
}).then(function(){ }).then(function(){
return context.setAsync("nodeX","foo","1"); return context.set("nodeX","foo","1");
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo") return context.get("nodeX","foo")
}).then(function(result){ }).then(function(result){
result.should.be.String(); result.should.be.String();
result.should.be.equal("1"); result.should.be.equal("1");
@ -106,11 +106,11 @@ describe('localfilesystem',function() {
}); });
it('should store number',function() { it('should store number',function() {
return context.getAsync("nodeX","foo").should.be.finally.undefined() return context.get("nodeX","foo").should.be.finally.undefined()
.then(function(){ .then(function(){
return context.setAsync("nodeX","foo",1); return context.set("nodeX","foo",1);
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo") return context.get("nodeX","foo")
}).then(function(result){ }).then(function(result){
result.should.be.Number(); result.should.be.Number();
result.should.be.equal(1); result.should.be.equal(1);
@ -118,33 +118,33 @@ describe('localfilesystem',function() {
}); });
it('should store null',function() { it('should store null',function() {
return context.getAsync("nodeX","foo").should.be.finally.undefined() return context.get("nodeX","foo").should.be.finally.undefined()
.then(function(){ .then(function(){
return context.setAsync("nodeX","foo",null); return context.set("nodeX","foo",null);
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo").should.be.finally.null(); return context.get("nodeX","foo").should.be.finally.null();
}); });
}); });
it('should store boolean',function() { it('should store boolean',function() {
return context.getAsync("nodeX","foo").should.be.finally.undefined() return context.get("nodeX","foo").should.be.finally.undefined()
.then(function(){ .then(function(){
return context.setAsync("nodeX","foo",true); return context.set("nodeX","foo",true);
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo").should.be.finally.Boolean().and.true(); return context.get("nodeX","foo").should.be.finally.Boolean().and.true();
}).then(function(){ }).then(function(){
return context.setAsync("nodeX","foo",false); return context.set("nodeX","foo",false);
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo").should.be.finally.Boolean().and.false(); return context.get("nodeX","foo").should.be.finally.Boolean().and.false();
}); });
}); });
it('should store object',function() { it('should store object',function() {
return context.getAsync("nodeX","foo").should.be.finally.undefined() return context.get("nodeX","foo").should.be.finally.undefined()
.then(function(){ .then(function(){
return context.setAsync("nodeX","foo",{obj:"bar"}); return context.set("nodeX","foo",{obj:"bar"});
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo") return context.get("nodeX","foo")
}).then(function(result){ }).then(function(result){
result.should.be.Object(); result.should.be.Object();
result.should.eql({obj:"bar"}); result.should.eql({obj:"bar"});
@ -152,16 +152,16 @@ describe('localfilesystem',function() {
}); });
it('should store array',function() { it('should store array',function() {
return context.getAsync("nodeX","foo").should.be.finally.undefined() return context.get("nodeX","foo").should.be.finally.undefined()
.then(function(){ .then(function(){
return context.setAsync("nodeX","foo",["a","b","c"]); return context.set("nodeX","foo",["a","b","c"]);
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo") return context.get("nodeX","foo")
}).then(function(result){ }).then(function(result){
result.should.be.Array(); result.should.be.Array();
result.should.eql(["a","b","c"]); result.should.eql(["a","b","c"]);
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo[1]") return context.get("nodeX","foo[1]")
}).then(function(result){ }).then(function(result){
result.should.be.String(); result.should.be.String();
result.should.equal("b"); result.should.equal("b");
@ -169,11 +169,11 @@ describe('localfilesystem',function() {
}); });
it('should store array of arrays',function() { it('should store array of arrays',function() {
return context.getAsync("nodeX","foo").should.be.finally.undefined() return context.get("nodeX","foo").should.be.finally.undefined()
.then(function(){ .then(function(){
return context.setAsync("nodeX","foo",[["a","b","c"],[1,2,3,4],[true,false]]); return context.set("nodeX","foo",[["a","b","c"],[1,2,3,4],[true,false]]);
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo") return context.get("nodeX","foo")
}).then(function(result){ }).then(function(result){
result.should.be.Array(); result.should.be.Array();
result.should.have.length(3); result.should.have.length(3);
@ -181,7 +181,7 @@ describe('localfilesystem',function() {
result[1].should.have.length(4); result[1].should.have.length(4);
result[2].should.have.length(2); result[2].should.have.length(2);
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo[1]") return context.get("nodeX","foo[1]")
}).then(function(result){ }).then(function(result){
result.should.be.Array(); result.should.be.Array();
result.should.have.length(4); result.should.have.length(4);
@ -190,11 +190,11 @@ describe('localfilesystem',function() {
}); });
it('should store array of objects',function() { it('should store array of objects',function() {
return context.getAsync("nodeX","foo").should.be.finally.undefined() return context.get("nodeX","foo").should.be.finally.undefined()
.then(function(){ .then(function(){
return context.setAsync("nodeX","foo",[{obj:"bar1"},{obj:"bar2"},{obj:"bar3"}]); return context.set("nodeX","foo",[{obj:"bar1"},{obj:"bar2"},{obj:"bar3"}]);
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo") return context.get("nodeX","foo")
}).then(function(result){ }).then(function(result){
result.should.be.Array(); result.should.be.Array();
result.should.have.length(3); result.should.have.length(3);
@ -202,7 +202,7 @@ describe('localfilesystem',function() {
result[1].should.be.Object(); result[1].should.be.Object();
result[2].should.be.Object(); result[2].should.be.Object();
}).then(function(){ }).then(function(){
return context.getAsync("nodeX","foo[1]") return context.get("nodeX","foo[1]")
}).then(function(result){ }).then(function(result){
result.should.be.Object(); result.should.be.Object();
result.should.be.eql({obj:"bar2"}); result.should.be.eql({obj:"bar2"});
@ -210,22 +210,22 @@ describe('localfilesystem',function() {
}); });
}); });
describe('#keysAsync',function() { describe('#keys',function() {
it('should enumerate context keys', function() { it('should enumerate context keys', function() {
return context.keysAsync("nodeX").then(function(result){ return context.keys("nodeX").then(function(result){
result.should.be.an.Array(); result.should.be.an.Array();
result.should.be.empty(); result.should.be.empty();
}).then(function(){ }).then(function(){
return context.setAsync("nodeX","foo","bar"); return context.set("nodeX","foo","bar");
}).then(function(){ }).then(function(){
return context.keysAsync("nodeX").then(function(result){ return context.keys("nodeX").then(function(result){
result.should.have.length(1); result.should.have.length(1);
result[0].should.equal("foo"); result[0].should.equal("foo");
}); });
}).then(function(){ }).then(function(){
return context.setAsync("nodeX","abc.def","bar"); return context.set("nodeX","abc.def","bar");
}).then(function(){ }).then(function(){
return context.keysAsync("nodeX").then(function(result){ return context.keys("nodeX").then(function(result){
result.should.have.length(2); result.should.have.length(2);
result[1].should.equal("abc"); result[1].should.equal("abc");
}); });
@ -233,19 +233,19 @@ describe('localfilesystem',function() {
}); });
it('should enumerate context keys in each scopes', function() { it('should enumerate context keys in each scopes', function() {
return Promise.all([context.keysAsync("nodeX"), return Promise.all([context.keys("nodeX"),
context.keysAsync("nodeY") context.keys("nodeY")
]).then(function(results){ ]).then(function(results){
results[0].should.be.an.Array(); results[0].should.be.an.Array();
results[0].should.be.empty(); results[0].should.be.empty();
results[1].should.be.an.Array(); results[1].should.be.an.Array();
results[1].should.be.empty(); results[1].should.be.empty();
}).then(function(){ }).then(function(){
return Promise.all([context.setAsync("nodeX","foo","bar"), return Promise.all([context.set("nodeX","foo","bar"),
context.setAsync("nodeY","hoge","piyo")]); context.set("nodeY","hoge","piyo")]);
}).then(function(){ }).then(function(){
return Promise.all([context.keysAsync("nodeX"), return Promise.all([context.keys("nodeX"),
context.keysAsync("nodeY")]); context.keys("nodeY")]);
}).then(function(results){ }).then(function(results){
results[0].should.have.length(1); results[0].should.have.length(1);
results[0][0].should.equal("foo"); results[0][0].should.equal("foo");
@ -257,55 +257,55 @@ describe('localfilesystem',function() {
describe('#delete',function() { describe('#delete',function() {
it('should delete context',function() { it('should delete context',function() {
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(), return Promise.all([context.get("nodeX","foo").should.be.finally.undefined(),
context.getAsync("nodeY","foo").should.be.finally.undefined() context.get("nodeY","foo").should.be.finally.undefined()
]).then(function(){ ]).then(function(){
return Promise.all([context.setAsync("nodeX","foo","abc"), return Promise.all([context.set("nodeX","foo","abc"),
context.setAsync("nodeY","foo","abc")]); context.set("nodeY","foo","abc")]);
}).then(function(){ }).then(function(){
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"), return Promise.all([context.get("nodeX","foo").should.be.finally.equal("abc"),
context.getAsync("nodeY","foo").should.be.finally.equal("abc")]) context.get("nodeY","foo").should.be.finally.equal("abc")])
}).then(function(){ }).then(function(){
return context.delete("nodeX"); return context.delete("nodeX");
}).then(function(){ }).then(function(){
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(), return Promise.all([context.get("nodeX","foo").should.be.finally.undefined(),
context.getAsync("nodeY","foo").should.be.finally.equal("abc")]); context.get("nodeY","foo").should.be.finally.equal("abc")]);
}); });
}); });
}); });
describe('#clean',function() { describe('#clean',function() {
it('should clean unnecessary context',function() { it('should clean unnecessary context',function() {
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(), return Promise.all([context.get("nodeX","foo").should.be.finally.undefined(),
context.getAsync("nodeY","foo").should.be.finally.undefined() context.get("nodeY","foo").should.be.finally.undefined()
]).then(function(){ ]).then(function(){
return Promise.all([context.setAsync("nodeX","foo","abc"), return Promise.all([context.set("nodeX","foo","abc"),
context.setAsync("nodeY","foo","abc")]); context.set("nodeY","foo","abc")]);
}).then(function(){ }).then(function(){
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"), return Promise.all([context.get("nodeX","foo").should.be.finally.equal("abc"),
context.getAsync("nodeY","foo").should.be.finally.equal("abc")]) context.get("nodeY","foo").should.be.finally.equal("abc")])
}).then(function(){ }).then(function(){
return context.clean([]); return context.clean([]);
}).then(function(){ }).then(function(){
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(), return Promise.all([context.get("nodeX","foo").should.be.finally.undefined(),
context.getAsync("nodeY","foo").should.be.finally.undefined()]); context.get("nodeY","foo").should.be.finally.undefined()]);
}); });
}); });
it('should not clean active context',function() { it('should not clean active context',function() {
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.undefined(), return Promise.all([context.get("nodeX","foo").should.be.finally.undefined(),
context.getAsync("nodeY","foo").should.be.finally.undefined() context.get("nodeY","foo").should.be.finally.undefined()
]).then(function(){ ]).then(function(){
return Promise.all([context.setAsync("nodeX","foo","abc"), return Promise.all([context.set("nodeX","foo","abc"),
context.setAsync("nodeY","foo","abc")]); context.set("nodeY","foo","abc")]);
}).then(function(){ }).then(function(){
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"), return Promise.all([context.get("nodeX","foo").should.be.finally.equal("abc"),
context.getAsync("nodeY","foo").should.be.finally.equal("abc")]) context.get("nodeY","foo").should.be.finally.equal("abc")])
}).then(function(){ }).then(function(){
return context.clean(["nodeX"]); return context.clean(["nodeX"]);
}).then(function(){ }).then(function(){
return Promise.all([context.getAsync("nodeX","foo").should.be.finally.equal("abc"), return Promise.all([context.get("nodeX","foo").should.be.finally.equal("abc"),
context.getAsync("nodeY","foo").should.be.finally.undefined()]); context.get("nodeY","foo").should.be.finally.undefined()]);
}); });
}); });
}); });