Merge pull request #533 from knolleary/deploy

Add smarter deployment options
This commit is contained in:
Nick O'Leary
2015-01-16 16:00:35 +00:00
27 changed files with 2341 additions and 682 deletions

View File

@@ -102,7 +102,7 @@ module.exports = {
credentials: credentials,
clearFlows: function() {
return flows.clear();
return flows.stopFlows();
},
request: function() {

View File

@@ -72,7 +72,7 @@ describe("flows api", function() {
});
it('returns error when set fails', function(done) {
var setFlows = sinon.stub(redNodes,'setFlows', function() {
return when.reject(new Error("test error"));
return when.reject(new Error("expected error"));
});
request(app)
.post('/flows')
@@ -83,7 +83,7 @@ describe("flows api", function() {
if (err) {
throw err;
}
res.text.should.eql("test error");
res.text.should.eql("expected error");
done();
});
});

821
test/red/nodes/Flow_spec.js Normal file
View File

@@ -0,0 +1,821 @@
/**
* Copyright 2015 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
var should = require("should");
var sinon = require('sinon');
var clone = require('clone');
var util = require("util");
var Flow = require("../../../red/nodes/Flow");
var flows = require("../../../red/nodes/flows");
var Node = require("../../../red/nodes/Node");
var typeRegistry = require("../../../red/nodes/registry");
var credentials = require("../../../red/nodes/credentials");
describe('Flow', function() {
describe('#constructor',function() {
it('called with an empty flow',function() {
var config = [];
var flow = new Flow(config);
config.should.eql(flow.getFlow());
var nodeCount = 0;
flow.eachNode(function(node) {
nodeCount++;
});
nodeCount.should.equal(0);
});
it('called with a non-empty flow with no missing types', function() {
var getType = sinon.stub(typeRegistry,"get",function(type) {
// For this test, don't care what the actual type is, just
// that this returns a non-false result
return {};
});
try {
var config = [{id:"123",type:"test"}];
var flow = new Flow(config);
config.should.eql(flow.getFlow());
flow.getMissingTypes().should.have.length(0);
} finally {
getType.restore();
}
});
it('identifies missing types in a flow', function() {
var getType = sinon.stub(typeRegistry,"get",function(type) {
if (type == "test") {
return {};
} else {
return null;
}
});
try {
var config = [{id:"123",type:"test"},{id:"456",type:"test1"},{id:"789",type:"test2"}];
var flow = new Flow(config);
config.should.eql(flow.getFlow());
flow.getMissingTypes().should.eql(["test1","test2"]);
} finally {
getType.restore();
}
});
it('extracts node credentials', function() {
var getType = sinon.stub(typeRegistry,"get",function(type) {
// For this test, don't care what the actual type is, just
// that this returns a non-false result
return {};
});
try {
var config = [{id:"123",type:"test",credentials:{a:1,b:2}}];
var resultingConfig = clone(config);
delete resultingConfig[0].credentials;
var flow = new Flow(config);
flow.getFlow().should.eql(resultingConfig);
flow.getMissingTypes().should.have.length(0);
} finally {
getType.restore();
}
});
});
describe('#start',function() {
it('prevents a flow with missing types from starting', function() {
var getType = sinon.stub(typeRegistry,"get",function(type) {
if (type == "test") {
return {};
} else {
return null;
}
});
try {
var config = [{id:"123",type:"test"},{id:"456",type:"test1"},{id:"789",type:"test2"}];
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(2);
/*jshint immed: false */
(function() {
flow.start();
}).should.throw();
} finally {
getType.restore();
}
});
});
describe('missing types',function() {
it('removes missing types as they are registered', function() {
var getType = sinon.stub(typeRegistry,"get",function(type) {
if (type == "test") {
return {};
} else {
return null;
}
});
var flowStart;
try {
var config = [{id:"123",type:"test"},{id:"456",type:"test1"},{id:"789",type:"test2"}];
var flow = new Flow(config);
flowStart = sinon.stub(flow,"start",function() {this.started = true;});
config.should.eql(flow.getFlow());
flow.getMissingTypes().should.eql(["test1","test2"]);
flow.typeRegistered("test1");
flow.getMissingTypes().should.eql(["test2"]);
flowStart.called.should.be.false;
flow.typeRegistered("test2");
flow.getMissingTypes().should.eql([]);
flowStart.called.should.be.false;
} finally {
flowStart.restore();
getType.restore();
}
});
it('starts flows once all missing types are registered', function() {
var getType = sinon.stub(typeRegistry,"get",function(type) {
if (type == "test") {
return {};
} else {
return null;
}
});
var flowStart;
try {
var config = [{id:"123",type:"test"},{id:"456",type:"test1"},{id:"789",type:"test2"}];
var flow = new Flow(config);
// First call to .start throws err due to missing types
/*jshint immed: false */
(function() {
flow.start();
}).should.throw();
// Stub .start so when missing types are registered, we don't actually try starting them
flowStart = sinon.stub(flow,"start",function() {});
config.should.eql(flow.getFlow());
flow.getMissingTypes().should.eql(["test1","test2"]);
flow.typeRegistered("test1");
flow.typeRegistered("test2");
flow.getMissingTypes().should.have.length(0);
flowStart.called.should.be.true;
} finally {
flowStart.restore();
getType.restore();
}
});
});
describe('#diffFlow',function() {
var getType;
before(function() {
getType = sinon.stub(typeRegistry,"get",function(type) {
// For this test, don't care what the actual type is, just
// that this returns a non-false result
return {};
});
});
after(function() {
getType.restore();
});
it('handles an identical configuration', function() {
var config = [{id:"123",type:"test",foo:"a",wires:[]}];
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(config);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",[]);
diffResult.should.have.property("linked",[]);
diffResult.should.have.property("wiringChanged",[]);
});
it('identifies nodes with changed properties, including downstream linked', function() {
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
var newConfig = clone(config);
newConfig[0].foo = "b";
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",["1"]);
diffResult.should.have.property("linked",["2"]);
diffResult.should.have.property("wiringChanged",[]);
});
it('identifies nodes with changed properties, including upstream linked', function() {
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
var newConfig = clone(config);
newConfig[1].bar = "c";
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",["2"]);
diffResult.should.have.property("linked",["1"]);
diffResult.should.have.property("wiringChanged",[]);
});
it('identifies nodes with changed credentials, including downstream linked', function() {
var config = [{id:"1",type:"test",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
var newConfig = clone(config);
newConfig[0].credentials = {};
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",["1"]);
diffResult.should.have.property("linked",["2"]);
diffResult.should.have.property("wiringChanged",[]);
});
it('identifies nodes with changed wiring', function() {
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
var newConfig = clone(config);
newConfig[1].wires[0][0] = 2;
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",[]);
diffResult.should.have.property("linked",["1","2"]);
diffResult.should.have.property("wiringChanged",["2"]);
});
it('identifies nodes with changed wiring - second connection added', function() {
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
var newConfig = clone(config);
newConfig[1].wires[0].push([1]);
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",[]);
diffResult.should.have.property("linked",["1","2"]);
diffResult.should.have.property("wiringChanged",["2"]);
});
it('identifies nodes with changed wiring - second connection added', function() {
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"2",type:"test",bar:"b",wires:[[1]]},{id:"3",type:"test",foo:"a",wires:[]}];
var newConfig = clone(config);
newConfig[1].wires[0].push([1]);
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",[]);
diffResult.should.have.property("linked",["1","2"]);
diffResult.should.have.property("wiringChanged",["2"]);
});
it('identifies nodes with changed wiring - node connected', function() {
var config = [{id:"1",type:"test",foo:"a",wires:[["2"]]},{id:"2",type:"test",bar:"b",wires:[[]]},{id:"3",type:"test",foo:"a",wires:[]}];
var newConfig = clone(config);
newConfig[1].wires.push("3");
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",[]);
diffResult.should.have.property("linked",["1","2","3"]);
diffResult.should.have.property("wiringChanged",["2"]);
});
it('identifies new nodes', function() {
var config = [{id:"1",type:"test",foo:"a",wires:[]},{id:"3",type:"test",foo:"a",wires:[]}];
var newConfig = clone(config);
newConfig.push({id:"2",type:"test",bar:"b",wires:[[1]]});
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",["2"]);
diffResult.should.have.property("linked",["1"]);
diffResult.should.have.property("wiringChanged",[]);
});
it('identifies deleted nodes', function() {
var config = [{id:"1",type:"test",foo:"a",wires:[[2]]},{id:"2",type:"test",bar:"b",wires:[[3]]},{id:"3",type:"test",foo:"a",wires:[]}];
var newConfig = clone(config);
newConfig.splice(1,1);
newConfig[0].wires = [];
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",["2"]);
diffResult.should.have.property("changed",[]);
diffResult.should.have.property("linked",["1","3"]);
diffResult.should.have.property("wiringChanged",["1"]);
});
it('identifies config nodes changes', function() {
var config = [{id:"1",type:"test",foo:"configNode",wires:[[2]]},{id:"2",type:"test",bar:"b",wires:[[3]]},{id:"3",type:"test",foo:"a",wires:[]},{id:"configNode",type:"testConfig"}];
var newConfig = clone(config);
newConfig[3].foo = "bar";
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",["1","configNode"]);
diffResult.should.have.property("linked",["2","3"]);
diffResult.should.have.property("wiringChanged",[]);
});
it('marks a parent subflow as changed for an internal property change', function() {
var config = [
{id:"1",type:"test",wires:[[2]]},
{id:"2",type:"subflow:sf1",wires:[[3]]},
{id:"3",type:"test",wires:[]},
{id:"sf1",type:"subflow"},
{id:"sf1-1",z:"sf1",type:"test",foo:"a"},
{id:"4",type:"subflow:sf1"}
];
var newConfig = clone(config);
newConfig[4].foo = "b";
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",["2","4"]);
diffResult.should.have.property("linked",["1","3"]);
diffResult.should.have.property("wiringChanged",[]);
});
it('marks a parent subflow as changed for an internal wiring change', function() {
var config = [
{id:"1",type:"test",wires:[[2]]},
{id:"2",type:"subflow:sf1",wires:[[3]]},
{id:"3",type:"test",wires:[]},
{id:"sf1",type:"subflow"},
{id:"sf1-1",z:"sf1",type:"test"},
{id:"sf1-2",z:"sf1",type:"test"}
];
var newConfig = clone(config);
newConfig[4].wires = [["sf1-2"]];
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",["2"]);
diffResult.should.have.property("linked",["1","3"]);
diffResult.should.have.property("wiringChanged",[]);
});
it('marks a parent subflow as changed for an internal node delete', function() {
var config = [
{id:"1",type:"test",wires:[[2]]},
{id:"2",type:"subflow:sf1",wires:[[3]]},
{id:"3",type:"test",wires:[]},
{id:"sf1",type:"subflow"},
{id:"sf1-1",z:"sf1",type:"test"},
{id:"sf1-2",z:"sf1",type:"test"}
];
var newConfig = clone(config);
newConfig.splice(5,1);
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",["2"]);
diffResult.should.have.property("linked",["1","3"]);
diffResult.should.have.property("wiringChanged",[]);
});
it('marks a parent subflow as changed for an internal subflow wiring change - input removed', function() {
var config = [
{id:"1",type:"test",wires:[[2]]},
{id:"2",type:"subflow:sf1",wires:[[3]]},
{id:"3",type:"test",wires:[]},
{id:"sf1",type:"subflow","in": [{"wires": [{"id": "sf1-1"}]}],"out": [{"wires": [{"id": "sf1-2","port": 0}]}]},
{id:"sf1-1",z:"sf1",type:"test"},
{id:"sf1-2",z:"sf1",type:"test"}
];
var newConfig = clone(config);
newConfig[3].in[0].wires = [];
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",["2"]);
diffResult.should.have.property("linked",["1","3"]);
diffResult.should.have.property("wiringChanged",[]);
});
it('marks a parent subflow as changed for an internal subflow wiring change - input added', function() {
var config = [
{id:"1",type:"test",wires:[[2]]},
{id:"2",type:"subflow:sf1",wires:[[3]]},
{id:"3",type:"test",wires:[]},
{id:"sf1",type:"subflow","in": [{"wires": [{"id": "sf1-1"}]}],"out": [{"wires": [{"id": "sf1-2","port": 0}]}]},
{id:"sf1-1",z:"sf1",type:"test"},
{id:"sf1-2",z:"sf1",type:"test"}
];
var newConfig = clone(config);
newConfig[3].in[0].wires.push({"id":"sf1-2"});
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",["2"]);
diffResult.should.have.property("linked",["1","3"]);
diffResult.should.have.property("wiringChanged",[]);
});
it('marks a parent subflow as changed for an internal subflow wiring change - output added', function() {
var config = [
{id:"1",type:"test",wires:[[2]]},
{id:"2",type:"subflow:sf1",wires:[[3]]},
{id:"3",type:"test",wires:[]},
{id:"sf1",type:"subflow","in": [{"wires": [{"id": "sf1-1"}]}],"out": [{"wires": [{"id": "sf1-2","port": 0}]}]},
{id:"sf1-1",z:"sf1",type:"test"},
{id:"sf1-2",z:"sf1",type:"test"}
];
var newConfig = clone(config);
newConfig[3].out[0].wires.push({"id":"sf1-2","port":0});
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",["2"]);
diffResult.should.have.property("linked",["1","3"]);
diffResult.should.have.property("wiringChanged",[]);
});
it('marks a parent subflow as changed for an internal subflow wiring change - output removed', function() {
var config = [
{id:"1",type:"test",wires:[[2]]},
{id:"2",type:"subflow:sf1",wires:[[3]]},
{id:"3",type:"test",wires:[]},
{id:"sf1",type:"subflow","in": [{"wires": [{"id": "sf1-1"}]}],"out": [{"wires": [{"id": "sf1-2","port": 0}]}]},
{id:"sf1-1",z:"sf1",type:"test"},
{id:"sf1-2",z:"sf1",type:"test"}
];
var newConfig = clone(config);
newConfig[3].out[0].wires = [];
var flow = new Flow(config);
flow.getMissingTypes().should.have.length(0);
var diffResult = flow.diffFlow(newConfig);
diffResult.should.have.property("deleted",[]);
diffResult.should.have.property("changed",["2"]);
diffResult.should.have.property("linked",["1","3"]);
diffResult.should.have.property("wiringChanged",[]);
});
});
describe('#applyConfig',function() {
var getType;
var getNode;
var flowsAdd;
var credentialsClean;
var stoppedNodes = {};
var currentNodes = {};
var TestNode = function(n) {
Node.call(this,n);
var node = this;
this.handled = 0;
this.stopped = false;
this.on('input',function(msg) {
node.handled++;
node.send(msg);
});
this.on('close',function() {
node.stopped = true;
stoppedNodes[node.id] = node;
delete currentNodes[node.id];
});
}
util.inherits(TestNode,Node);
before(function() {
flowsAdd = sinon.stub(flows,"add",function(node) {
currentNodes[node.id] = node;
});
getNode = sinon.stub(flows,"get",function(id) {
return currentNodes[id];
});
getType = sinon.stub(typeRegistry,"get",function(type) {
return TestNode;
});
credentialsClean = sinon.stub(credentials,"clean",function(config){});
});
after(function() {
getType.restore();
flowsAdd.restore();
credentialsClean.restore();
getNode.restore();
});
beforeEach(function() {
currentNodes = {};
stoppedNodes = {};
});
it("instantiates an initial configuration and stops it",function(done) {
var config = [{id:"1",type:"test",foo:"a",wires:["2"]},{id:"2",type:"test",bar:"b",wires:[["3"]]},{id:"3",type:"test",foo:"a",wires:[]}];
var flow = new Flow(config);
flow.start();
currentNodes.should.have.a.property("1");
currentNodes.should.have.a.property("2");
currentNodes.should.have.a.property("3");
currentNodes["1"].should.have.a.property("handled",0);
currentNodes["2"].should.have.a.property("handled",0);
currentNodes["3"].should.have.a.property("handled",0);
currentNodes["1"].receive({payload:"test"});
currentNodes["1"].should.have.a.property("handled",1);
currentNodes["2"].should.have.a.property("handled",1);
currentNodes["3"].should.have.a.property("handled",1);
flow.stop().then(function() {
currentNodes.should.not.have.a.property("1");
currentNodes.should.not.have.a.property("2");
currentNodes.should.not.have.a.property("3");
stoppedNodes.should.have.a.property("1");
stoppedNodes.should.have.a.property("2");
stoppedNodes.should.have.a.property("3");
done();
});
});
it("stops all nodes on new full deploy",function(done) {
var config = [{id:"1",type:"test",foo:"a",wires:["2"]},{id:"2",type:"test",bar:"b",wires:[["3"]]},{id:"3",type:"test",foo:"a",wires:[]}];
var newConfig = [{id:"4",type:"test",foo:"a",wires:["5"]},{id:"5",type:"test",bar:"b",wires:[["6"]]},{id:"6",type:"test",foo:"a",wires:[]}];
var flow = new Flow(config);
flow.start();
currentNodes.should.have.a.property("1");
currentNodes.should.have.a.property("2");
currentNodes.should.have.a.property("3");
flow.applyConfig(newConfig).then(function() {
currentNodes.should.not.have.a.property("1");
currentNodes.should.not.have.a.property("2");
currentNodes.should.not.have.a.property("3");
stoppedNodes.should.have.a.property("1");
stoppedNodes.should.have.a.property("2");
stoppedNodes.should.have.a.property("3");
currentNodes.should.have.a.property("4");
currentNodes.should.have.a.property("5");
currentNodes.should.have.a.property("6");
done();
});
});
it("stops only modified nodes on 'nodes' deploy",function(done) {
var config = [{id:"1",type:"test",name:"a",wires:["2"]},{id:"2",type:"test",name:"b",wires:[["3"]]},{id:"3",type:"test",name:"c",wires:[]}];
var newConfig = clone(config);
newConfig[1].name = "B";
var flow = new Flow(config);
flow.start();
currentNodes.should.have.a.property("1");
currentNodes.should.have.a.property("2");
currentNodes.should.have.a.property("3");
currentNodes["2"].should.have.a.property("name","b");
currentNodes["1"].receive({payload:"test"});
currentNodes["1"].should.have.a.property("handled",1);
currentNodes["2"].should.have.a.property("handled",1);
currentNodes["3"].should.have.a.property("handled",1);
flow.applyConfig(newConfig,"nodes").then(function() {
currentNodes.should.have.a.property("1");
currentNodes.should.have.a.property("2");
currentNodes.should.have.a.property("3");
currentNodes["2"].should.have.a.property("name","B");
stoppedNodes.should.not.have.a.property("1");
stoppedNodes.should.have.a.property("2");
stoppedNodes.should.not.have.a.property("3");
stoppedNodes["2"].should.have.a.property("name","b");
currentNodes["1"].receive({payload:"test"});
currentNodes["1"].should.have.a.property("handled",2);
currentNodes["2"].should.have.a.property("handled",1);
currentNodes["3"].should.have.a.property("handled",2);
done();
});
});
it("stops only modified flows on 'flows' deploy",function(done) {
var config = [{id:"1",type:"test",name:"a",wires:["2"]},{id:"2",type:"test",name:"b",wires:[[]]},{id:"3",type:"test",name:"c",wires:[]}];
var newConfig = clone(config);
newConfig[1].name = "B";
var flow = new Flow(config);
flow.start();
currentNodes.should.have.a.property("1");
currentNodes.should.have.a.property("2");
currentNodes.should.have.a.property("3");
currentNodes["2"].should.have.a.property("name","b");
currentNodes["1"].receive({payload:"test"});
currentNodes["1"].should.have.a.property("handled",1);
currentNodes["2"].should.have.a.property("handled",1);
currentNodes["3"].should.have.a.property("handled",0);
currentNodes["3"].receive({payload:"test"});
currentNodes["3"].should.have.a.property("handled",1);
flow.applyConfig(newConfig,"flows").then(function() {
currentNodes.should.have.a.property("1");
currentNodes.should.have.a.property("2");
currentNodes.should.have.a.property("3");
currentNodes["2"].should.have.a.property("name","B");
stoppedNodes.should.have.a.property("1");
stoppedNodes.should.have.a.property("2");
stoppedNodes.should.not.have.a.property("3");
stoppedNodes["2"].should.have.a.property("name","b");
currentNodes["1"].receive({payload:"test"});
currentNodes["1"].should.have.a.property("handled",1);
currentNodes["2"].should.have.a.property("handled",1);
currentNodes["3"].receive({payload:"test"});
currentNodes["3"].should.have.a.property("handled",2);
done();
});
});
it("rewires otherwise unmodified nodes on 'nodes' deploy",function(done) {
var config = [{id:"1",type:"test",name:"a",wires:["2"]},{id:"2",type:"test",name:"b",wires:[[]]},{id:"3",type:"test",name:"c",wires:[]}];
var newConfig = clone(config);
newConfig[1].wires[0].push("3");
var flow = new Flow(config);
flow.start();
currentNodes.should.have.a.property("1");
currentNodes.should.have.a.property("2");
currentNodes.should.have.a.property("3");
currentNodes["1"].receive({payload:"test"});
currentNodes["1"].should.have.a.property("handled",1);
currentNodes["2"].should.have.a.property("handled",1);
currentNodes["3"].should.have.a.property("handled",0);
flow.applyConfig(newConfig,"nodes").then(function() {
currentNodes.should.have.a.property("1");
currentNodes.should.have.a.property("2");
currentNodes.should.have.a.property("3");
stoppedNodes.should.not.have.a.property("1");
stoppedNodes.should.not.have.a.property("2");
stoppedNodes.should.not.have.a.property("3");
currentNodes["1"].receive({payload:"test"});
currentNodes["1"].should.have.a.property("handled",2);
currentNodes["2"].should.have.a.property("handled",2);
currentNodes["3"].should.have.a.property("handled",1);
done();
});
});
it("stops rewired but otherwise unmodified nodes on 'flows' deploy",function(done) {
var config = [{id:"1",type:"test",name:"a",wires:["2"]},{id:"2",type:"test",name:"b",wires:[[]]},{id:"3",type:"test",name:"c",wires:[]}];
var newConfig = clone(config);
newConfig[1].wires[0].push("3");
var flow = new Flow(config);
flow.start();
currentNodes.should.have.a.property("1");
currentNodes.should.have.a.property("2");
currentNodes.should.have.a.property("3");
currentNodes["1"].receive({payload:"test"});
currentNodes["1"].should.have.a.property("handled",1);
currentNodes["2"].should.have.a.property("handled",1);
currentNodes["3"].should.have.a.property("handled",0);
flow.applyConfig(newConfig,"flows").then(function() {
currentNodes.should.have.a.property("1");
currentNodes.should.have.a.property("2");
currentNodes.should.have.a.property("3");
stoppedNodes.should.have.a.property("1");
stoppedNodes.should.have.a.property("2");
stoppedNodes.should.have.a.property("3");
currentNodes["1"].receive({payload:"test"});
currentNodes["1"].should.have.a.property("handled",1);
currentNodes["2"].should.have.a.property("handled",1);
currentNodes["3"].should.have.a.property("handled",1);
done();
});
});
});
});

View File

@@ -17,6 +17,8 @@
var should = require("should");
var sinon = require('sinon');
var RedNode = require("../../../red/nodes/Node");
var flows = require("../../../red/nodes/flows");
var comms = require('../../../red/comms');
describe('Node', function() {
@@ -90,12 +92,16 @@ describe('Node', function() {
it('emits a single message', function(done) {
var n1 = new RedNode({id:'n1',type:'abc',wires:[['n2']]});
var n2 = new RedNode({id:'n2',type:'abc'});
var flowGet = sinon.stub(flows,"get",function(id) {
return {'n1':n1,'n2':n2}[id];
});
var message = {payload:"hello world"};
n2.on('input',function(msg) {
// msg equals message, and is not a new copy
should.deepEqual(msg,message);
should.strictEqual(msg,message);
flowGet.restore();
done();
});
@@ -105,6 +111,9 @@ describe('Node', function() {
it('emits multiple messages on a single output', function(done) {
var n1 = new RedNode({id:'n1',type:'abc',wires:[['n2']]});
var n2 = new RedNode({id:'n2',type:'abc'});
var flowGet = sinon.stub(flows,"get",function(id) {
return {'n1':n1,'n2':n2}[id];
});
var messages = [
{payload:"hello world"},
@@ -126,6 +135,7 @@ describe('Node', function() {
rcvdCount += 1;
if (rcvdCount === 2) {
flowGet.restore();
done();
}
});
@@ -138,6 +148,9 @@ describe('Node', function() {
var n3 = new RedNode({id:'n3',type:'abc'});
var n4 = new RedNode({id:'n4',type:'abc'});
var n5 = new RedNode({id:'n5',type:'abc'});
var flowGet = sinon.stub(flows,"get",function(id) {
return {'n1':n1,'n2':n2,'n3':n3,'n4':n4,'n5':n5}[id];
});
var messages = [
{payload:"hello world"},
@@ -153,6 +166,7 @@ describe('Node', function() {
should.strictEqual(msg,messages[0]);
rcvdCount += 1;
if (rcvdCount == 3) {
flowGet.restore();
done();
}
});
@@ -167,6 +181,7 @@ describe('Node', function() {
should.notStrictEqual(msg,messages[2]);
rcvdCount += 1;
if (rcvdCount == 3) {
flowGet.restore();
done();
}
});
@@ -177,6 +192,7 @@ describe('Node', function() {
should.notStrictEqual(msg,messages[2]);
rcvdCount += 1;
if (rcvdCount == 3) {
flowGet.restore();
done();
}
});
@@ -187,12 +203,16 @@ describe('Node', function() {
it('emits no messages', function(done) {
var n1 = new RedNode({id:'n1',type:'abc',wires:[['n2']]});
var n2 = new RedNode({id:'n2',type:'abc'});
var flowGet = sinon.stub(flows,"get",function(id) {
return {'n1':n1,'n2':n2}[id];
});
n2.on('input',function(msg) {
should.fail(null,null,"unexpected message");
});
setTimeout(function() {
flowGet.restore();
done();
}, 200);
@@ -202,7 +222,10 @@ describe('Node', function() {
it('emits messages ignoring non-existent nodes', function(done) {
var n1 = new RedNode({id:'n1',type:'abc',wires:[['n9'],['n2']]});
var n2 = new RedNode({id:'n2',type:'abc'});
var flowGet = sinon.stub(flows,"get",function(id) {
return {'n1':n1,'n2':n2}[id];
});
var messages = [
{payload:"hello world"},
{payload:"hello world again"}
@@ -212,6 +235,7 @@ describe('Node', function() {
n2.on('input',function(msg) {
should.deepEqual(msg,messages[1]);
should.strictEqual(msg,messages[1]);
flowGet.restore();
done();
});
@@ -222,6 +246,9 @@ describe('Node', function() {
var n1 = new RedNode({id:'n1',type:'abc',wires:[['n2'],['n3']]});
var n2 = new RedNode({id:'n2',type:'abc'});
var n3 = new RedNode({id:'n3',type:'abc'});
var flowGet = sinon.stub(flows,"get",function(id) {
return {'n1':n1,'n2':n2,'n3':n3}[id];
});
var req = {};
var res = {};
@@ -234,6 +261,7 @@ describe('Node', function() {
msg.cloned.should.be.exactly(message.cloned);
msg.req.should.be.exactly(message.req);
msg.res.should.be.exactly(message.res);
flowGet.restore();
done();
});
@@ -243,6 +271,7 @@ describe('Node', function() {
msg.cloned.should.not.be.exactly(message.cloned);
msg.req.should.be.exactly(message.req);
msg.res.should.be.exactly(message.res);
flowGet.restore();
done();
});

View File

@@ -112,9 +112,7 @@ describe('Credentials', function() {
credentials.init(storage);
credentials.load().then(function() {
should.exist(credentials.get("a"));
credentials.clean(function() {
return false;
});
credentials.clean([]);
storage.saveCredentials.callCount.should.be.exactly(1);
should.not.exist(credentials.get("a"));
storage.saveCredentials.restore();
@@ -211,287 +209,287 @@ describe('Credentials', function() {
});
});
describe('extract and store credential updates in the provided node', function() {
var path = require('path');
var fs = require('fs-extra');
var http = require('http');
var express = require('express');
var server = require("../../../red/server");
var localfilesystem = require("../../../red/storage/localfilesystem");
var app = express();
var RED = require("../../../red/red.js");
var userDir = path.join(__dirname,".testUserHome");
before(function(done) {
fs.remove(userDir,function(err) {
fs.mkdir(userDir,function() {
sinon.stub(index, 'load', function() {
return when.promise(function(resolve,reject){
resolve([]);
});
});
sinon.stub(localfilesystem, 'getCredentials', function() {
return when.promise(function(resolve,reject) {
resolve({"tab1":{"foo": 2, "pswd":'sticks'}});
});
}) ;
RED.init(http.createServer(function(req,res){app(req,res)}),
{userDir: userDir});
server.start().then(function () {
done();
});
});
});
});
after(function(done) {
fs.remove(userDir,done);
server.stop();
index.load.restore();
localfilesystem.getCredentials.restore();
});
function TestNode(n) {
index.createNode(this, n);
var node = this;
this.on("log", function() {
// do nothing
});
}
it(': credential updated with good value', function(done) {
index.registerType('test', TestNode, {
credentials: {
foo: {type:"test"}
}
});
index.loadFlows().then(function() {
var testnode = new TestNode({id:'tab1',type:'test',name:'barney'});
credentials.extract(testnode);
should.exist(credentials.get('tab1'));
credentials.get('tab1').should.have.property('foo',2);
// set credentials to be an updated value and checking this is extracted properly
testnode.credentials = {"foo": 3};
credentials.extract(testnode);
should.exist(credentials.get('tab1'));
credentials.get('tab1').should.not.have.property('foo',2);
credentials.get('tab1').should.have.property('foo',3);
done();
}).otherwise(function(err){
done(err);
});
});
//describe('extract and store credential updates in the provided node', function() {
// var path = require('path');
// var fs = require('fs-extra');
// var http = require('http');
// var express = require('express');
// var server = require("../../../red/server");
// var localfilesystem = require("../../../red/storage/localfilesystem");
// var app = express();
// var RED = require("../../../red/red.js");
//
// var userDir = path.join(__dirname,".testUserHome");
// before(function(done) {
// fs.remove(userDir,function(err) {
// fs.mkdir(userDir,function() {
// sinon.stub(index, 'load', function() {
// return when.promise(function(resolve,reject){
// resolve([]);
// });
// });
// sinon.stub(localfilesystem, 'getCredentials', function() {
// return when.promise(function(resolve,reject) {
// resolve({"tab1":{"foo": 2, "pswd":'sticks'}});
// });
// }) ;
// RED.init(http.createServer(function(req,res){app(req,res)}),
// {userDir: userDir});
// server.start().then(function () {
// done();
// });
// });
// });
// });
//
// after(function(done) {
// fs.remove(userDir,done);
// server.stop();
// index.load.restore();
// localfilesystem.getCredentials.restore();
// });
//
// function TestNode(n) {
// index.createNode(this, n);
// var node = this;
// this.on("log", function() {
// // do nothing
// });
// }
//
// it(': credential updated with good value', function(done) {
// index.registerType('test', TestNode, {
// credentials: {
// foo: {type:"test"}
// }
// });
// index.loadFlows().then(function() {
// var testnode = new TestNode({id:'tab1',type:'test',name:'barney'});
// credentials.extract(testnode);
// should.exist(credentials.get('tab1'));
// credentials.get('tab1').should.have.property('foo',2);
//
// // set credentials to be an updated value and checking this is extracted properly
// testnode.credentials = {"foo": 3};
// credentials.extract(testnode);
// should.exist(credentials.get('tab1'));
// credentials.get('tab1').should.not.have.property('foo',2);
// credentials.get('tab1').should.have.property('foo',3);
// done();
// }).otherwise(function(err){
// done(err);
// });
// });
//
// it(': credential updated with empty value', function(done) {
// index.registerType('test', TestNode, {
// credentials: {
// foo: {type:"test"}
// }
// });
// index.loadFlows().then(function() {
// var testnode = new TestNode({id:'tab1',type:'test',name:'barney'});
// // setting value of "foo" credential to be empty removes foo as a property
// testnode.credentials = {"foo": ''};
// credentials.extract(testnode);
// should.exist(credentials.get('tab1'));
// credentials.get('tab1').should.not.have.property('foo',2);
// credentials.get('tab1').should.not.have.property('foo');
// done();
// }).otherwise(function(err){
// done(err);
// });
// });
//
// it(': undefined credential updated', function(done) {
// index.registerType('test', TestNode, {
// credentials: {
// foo: {type:"test"}
// }
// });
// index.loadFlows().then(function() {
// var testnode = new TestNode({id:'tab1',type:'test',name:'barney'});
// // setting value of an undefined credential should not change anything
// testnode.credentials = {"bar": 4};
// credentials.extract(testnode);
// should.exist(credentials.get('tab1'));
// credentials.get('tab1').should.have.property('foo',2);
// credentials.get('tab1').should.not.have.property('bar');
// done();
// }).otherwise(function(err){
// done(err);
// });
// });
//
// it(': password credential updated', function(done) {
// index.registerType('password', TestNode, {
// credentials: {
// pswd: {type:"password"}
// }
// });
// index.loadFlows().then(function() {
// var testnode = new TestNode({id:'tab1',type:'password',name:'barney'});
// // setting value of password credential should update password
// testnode.credentials = {"pswd": 'fiddle'};
// credentials.extract(testnode);
// should.exist(credentials.get('tab1'));
// credentials.get('tab1').should.have.property('pswd','fiddle');
// credentials.get('tab1').should.not.have.property('pswd','sticks');
// done();
// }).otherwise(function(err){
// done(err);
// });
// });
//
// it(': password credential not updated', function(done) {
// index.registerType('password', TestNode, {
// credentials: {
// pswd: {type:"password"}
// }
// });
// index.loadFlows().then(function() {
// var testnode = new TestNode({id:'tab1',type:'password',name:'barney'});
// // setting value of password credential should update password
// testnode.credentials = {"pswd": '__PWRD__'};
// credentials.extract(testnode);
// should.exist(credentials.get('tab1'));
// credentials.get('tab1').should.have.property('pswd','sticks');
// credentials.get('tab1').should.not.have.property('pswd','__PWRD__');
// done();
// }).otherwise(function(err){
// done(err);
// });
// });
//
//})
it(': credential updated with empty value', function(done) {
index.registerType('test', TestNode, {
credentials: {
foo: {type:"test"}
}
});
index.loadFlows().then(function() {
var testnode = new TestNode({id:'tab1',type:'test',name:'barney'});
// setting value of "foo" credential to be empty removes foo as a property
testnode.credentials = {"foo": ''};
credentials.extract(testnode);
should.exist(credentials.get('tab1'));
credentials.get('tab1').should.not.have.property('foo',2);
credentials.get('tab1').should.not.have.property('foo');
done();
}).otherwise(function(err){
done(err);
});
});
it(': undefined credential updated', function(done) {
index.registerType('test', TestNode, {
credentials: {
foo: {type:"test"}
}
});
index.loadFlows().then(function() {
var testnode = new TestNode({id:'tab1',type:'test',name:'barney'});
// setting value of an undefined credential should not change anything
testnode.credentials = {"bar": 4};
credentials.extract(testnode);
should.exist(credentials.get('tab1'));
credentials.get('tab1').should.have.property('foo',2);
credentials.get('tab1').should.not.have.property('bar');
done();
}).otherwise(function(err){
done(err);
});
});
it(': password credential updated', function(done) {
index.registerType('password', TestNode, {
credentials: {
pswd: {type:"password"}
}
});
index.loadFlows().then(function() {
var testnode = new TestNode({id:'tab1',type:'password',name:'barney'});
// setting value of password credential should update password
testnode.credentials = {"pswd": 'fiddle'};
credentials.extract(testnode);
should.exist(credentials.get('tab1'));
credentials.get('tab1').should.have.property('pswd','fiddle');
credentials.get('tab1').should.not.have.property('pswd','sticks');
done();
}).otherwise(function(err){
done(err);
});
});
it(': password credential not updated', function(done) {
index.registerType('password', TestNode, {
credentials: {
pswd: {type:"password"}
}
});
index.loadFlows().then(function() {
var testnode = new TestNode({id:'tab1',type:'password',name:'barney'});
// setting value of password credential should update password
testnode.credentials = {"pswd": '__PWRD__'};
credentials.extract(testnode);
should.exist(credentials.get('tab1'));
credentials.get('tab1').should.have.property('pswd','sticks');
credentials.get('tab1').should.not.have.property('pswd','__PWRD__');
done();
}).otherwise(function(err){
done(err);
});
});
})
describe('registerEndpoint', function() {
var path = require('path');
var fs = require('fs-extra');
var http = require('http');
var express = require('express');
var request = require('supertest');
var server = require("../../../red/server");
var localfilesystem = require("../../../red/storage/localfilesystem");
var app = express();
var RED = require("../../../red/red.js");
var userDir = path.join(__dirname,".testUserHome");
before(function(done) {
fs.remove(userDir,function(err) {
fs.mkdir(userDir,function() {
sinon.stub(index, 'load', function() {
return when.promise(function(resolve,reject){
resolve([]);
});
});
sinon.stub(localfilesystem, 'getCredentials', function() {
return when.promise(function(resolve,reject) {
resolve({"tab1":{"foo": 2, "pswd":'sticks'}});
});
}) ;
RED.init(http.createServer(function(req,res){app(req,res)}),
{userDir: userDir});
server.start().then(function () {
done();
});
});
});
});
after(function(done) {
fs.remove(userDir,done);
server.stop();
index.load.restore();
localfilesystem.getCredentials.restore();
});
function TestNode(n) {
index.createNode(this, n);
var node = this;
this.on("log", function() {
// do nothing
});
}
it(': valid credential type', function(done) {
index.registerType('test', TestNode, {
credentials: {
foo: {type:"test"}
}
});
index.loadFlows().then(function() {
var testnode = new TestNode({id:'tab1',type:'foo',name:'barney'});
request(RED.httpAdmin).get('/credentials/test/tab1').expect(200).end(function(err,res) {
if (err) {
done(err);
}
res.body.should.have.property('foo', 2);
done();
});
}).otherwise(function(err){
done(err);
});
});
it(': password credential type', function(done) {
index.registerType('password', TestNode, {
credentials: {
pswd: {type:"password"}
}
});
index.loadFlows().then(function() {
var testnode = new TestNode({id:'tab1',type:'pswd',name:'barney'});
request(RED.httpAdmin).get('/credentials/password/tab1').expect(200).end(function(err,res) {
if (err) {
done(err);
}
res.body.should.have.property('has_pswd', true);
res.body.should.not.have.property('pswd');
done();
});
}).otherwise(function(err){
done(err);
});
});
it(': returns 404 for undefined credential type', function(done) {
index.registerType('test', TestNode, {
credentials: {
foo: {type:"test"}
}
});
index.loadFlows().then(function() {
var testnode = new TestNode({id:'tab1',type:'foo',name:'barney'});
request(RED.httpAdmin).get('/credentials/unknownType/tab1').expect(404).end(done);
}).otherwise(function(err){
done(err);
});
});
it(': undefined nodeID', function(done) {
index.registerType('test', TestNode, {
credentials: {
foo: {type:"test"}
}
});
index.loadFlows().then(function() {
var testnode = new TestNode({id:'tab1',type:'foo',name:'barney'});
request(RED.httpAdmin).get('/credentials/test/unknownNode').expect(200).end(function(err,res) {
if (err) {
done(err);
}
var b = res.body;
res.body.should.not.have.property('foo');
done();
});
}).otherwise(function(err){
done(err);
});
});
})
//describe('registerEndpoint', function() {
// var path = require('path');
// var fs = require('fs-extra');
// var http = require('http');
// var express = require('express');
// var request = require('supertest');
//
// var server = require("../../../red/server");
// var localfilesystem = require("../../../red/storage/localfilesystem");
// var app = express();
// var RED = require("../../../red/red.js");
//
// var userDir = path.join(__dirname,".testUserHome");
// before(function(done) {
// fs.remove(userDir,function(err) {
// fs.mkdir(userDir,function() {
// sinon.stub(index, 'load', function() {
// return when.promise(function(resolve,reject){
// resolve([]);
// });
// });
// sinon.stub(localfilesystem, 'getCredentials', function() {
// return when.promise(function(resolve,reject) {
// resolve({"tab1":{"foo": 2, "pswd":'sticks'}});
// });
// }) ;
// RED.init(http.createServer(function(req,res){app(req,res)}),
// {userDir: userDir});
// server.start().then(function () {
// done();
// });
// });
// });
// });
//
// after(function(done) {
// fs.remove(userDir,done);
// server.stop();
// index.load.restore();
// localfilesystem.getCredentials.restore();
// });
//
// function TestNode(n) {
// index.createNode(this, n);
// var node = this;
// this.on("log", function() {
// // do nothing
// });
// }
//
// it(': valid credential type', function(done) {
// index.registerType('test', TestNode, {
// credentials: {
// foo: {type:"test"}
// }
// });
// index.loadFlows().then(function() {
// var testnode = new TestNode({id:'tab1',type:'foo',name:'barney'});
// request(RED.httpAdmin).get('/credentials/test/tab1').expect(200).end(function(err,res) {
// if (err) {
// done(err);
// }
// res.body.should.have.property('foo', 2);
// done();
// });
// }).otherwise(function(err){
// done(err);
// });
// });
//
// it(': password credential type', function(done) {
// index.registerType('password', TestNode, {
// credentials: {
// pswd: {type:"password"}
// }
// });
// index.loadFlows().then(function() {
// var testnode = new TestNode({id:'tab1',type:'pswd',name:'barney'});
// request(RED.httpAdmin).get('/credentials/password/tab1').expect(200).end(function(err,res) {
// if (err) {
// done(err);
// }
// res.body.should.have.property('has_pswd', true);
// res.body.should.not.have.property('pswd');
// done();
// });
// }).otherwise(function(err){
// done(err);
// });
// });
//
// it(': returns 404 for undefined credential type', function(done) {
// index.registerType('test', TestNode, {
// credentials: {
// foo: {type:"test"}
// }
// });
// index.loadFlows().then(function() {
// var testnode = new TestNode({id:'tab1',type:'foo',name:'barney'});
// request(RED.httpAdmin).get('/credentials/unknownType/tab1').expect(404).end(done);
// }).otherwise(function(err){
// done(err);
// });
// });
//
// it(': undefined nodeID', function(done) {
// index.registerType('test', TestNode, {
// credentials: {
// foo: {type:"test"}
// }
// });
// index.loadFlows().then(function() {
// var testnode = new TestNode({id:'tab1',type:'foo',name:'barney'});
// request(RED.httpAdmin).get('/credentials/test/unknownNode').expect(200).end(function(err,res) {
// if (err) {
// done(err);
// }
// var b = res.body;
// res.body.should.not.have.property('foo');
// done();
// });
// }).otherwise(function(err){
// done(err);
// });
// });
//
//})
})

View File

@@ -47,39 +47,13 @@ function loadFlows(testFlows, cb) {
describe('flows', function() {
afterEach(function(done) {
flows.clear().then(function() {
flows.stopFlows().then(function() {
loadFlows([],done);
});
});
describe('#add',function() {
it('should be called by node constructor',function(done) {
var n = new RedNode({id:'123',type:'abc'});
should.deepEqual(n, flows.get("123"));
flows.clear().then(function() {
done();
});
});
});
describe('#each',function() {
it('should "visit" all nodes',function(done) {
var nodes = [
new RedNode({id:'n0'}),
new RedNode({id:'n1'})
];
var count = 0;
flows.each(function(node) {
should.deepEqual(nodes[count], node);
count += 1;
if (count == 2) {
done();
}
});
});
});
describe('#load',function() {
it('should load nothing when storage is empty',function(done) {
loadFlows([], done);
});
@@ -92,7 +66,7 @@ describe('flows', function() {
it('should load and start a registered node type', function(done) {
RED.registerType('debug', function() {});
var typeRegistryGet = sinon.stub(typeRegistry,"get",function(nt) {
return function() {};
return RedNode;
});
loadFlows([{"id":"n1","type":"debug"}], function() { });
events.once('nodes-started', function() {
@@ -104,8 +78,7 @@ describe('flows', function() {
it('should load and start when node type is registered', function(done) {
var typeRegistryGet = sinon.stub(typeRegistry,"get");
typeRegistryGet.onCall(0).returns(null);
typeRegistryGet.returns(function(){});
typeRegistryGet.returns(RedNode);
loadFlows([{"id":"n2","type":"inject"}], function() {
events.emit('type-registered','inject');
});
@@ -118,7 +91,7 @@ describe('flows', function() {
it('should not instantiate nodes of an unused subflow', function(done) {
RED.registerType('abc', function() {});
var typeRegistryGet = sinon.stub(typeRegistry,"get",function(nt) {
return function() {};
return RedNode;
});
loadFlows([{"id":"n1","type":"subflow",inputs:[],outputs:[],wires:[]},
{"id":"n2","type":"abc","z":"n1",wires:[]}
@@ -126,11 +99,10 @@ describe('flows', function() {
events.once('nodes-started', function() {
(flows.get("n2") == null).should.be.true;
var ncount = 0
flows.each(function(n) {
flows.eachNode(function(n) {
ncount++;
});
ncount.should.equal(0);
console.log(ncount);
typeRegistryGet.restore();
done();
});
@@ -149,7 +121,7 @@ describe('flows', function() {
(flows.get("n2") == null).should.be.true;
var ncount = 0
var nodes = [];
flows.each(function(n) {
flows.eachNode(function(n) {
nodes.push(n);
});
nodes.should.have.lengthOf(2);

View File

@@ -41,16 +41,6 @@ describe('NodeRegistry', function() {
var settings = stubSettings({},false);
var settingsWithStorage = stubSettings({},true);
it('automatically registers new nodes',function() {
var testNode = RedNodes.getNode('123');
should.not.exist(n);
var n = new RedNode({id:'123',type:'abc'});
var newNode = RedNodes.getNode('123');
should.strictEqual(n,newNode);
});
it('handles nodes that export a function', function(done) {
typeRegistry.init(settings);
typeRegistry.load(resourcesDir + "TestNode1",true).then(function() {
@@ -239,11 +229,12 @@ describe('NodeRegistry', function() {
});
});
it('returns nothing for an unregistered type config', function() {
it('returns nothing for an unregistered type config', function(done) {
typeRegistry.init(settings);
typeRegistry.load("wontexist",true).then(function(){
var config = typeRegistry.getNodeConfig("imaginary-shark");
(config === null).should.be.true;
done();
}).catch(function(e) {
done(e);
});