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

update test cases

This commit is contained in:
Hiroyasu Nishiyama 2019-01-28 23:14:49 +09:00
parent f88a4b1791
commit 0881c6a20b
3 changed files with 36 additions and 24 deletions

View File

@ -208,39 +208,37 @@ class Subflow extends Flow {
} }
return null; return null;
} }
function lookupFlow0(env, name) { function lookupFlow0(flow, name) {
if (flow.subflowInstance) { if (flow.subflowInstance && flow.subflowInstance.env) {
var vi = lookup(flow.subflowInstance.env, name); var val = lookup(flow.subflowInstance.env, name);
if (vi) { if (val) {
return vi; return val;
} }
} }
if (flow.subflowDef) { if (flow.subflowDef && flow.subflowDef.env) {
var vt = lookup(flow.subflowDef.env, name); var val = lookup(flow.subflowDef.env, name);
if (vt) { if (val) {
return vt; return val;
} }
} }
return null; return null;
} }
function lookupFlow(flow, name) {
function lookupFlow(env, name) { var prefix = name.substring(0, name.length -5); // len("_{type,info}")==5
if (name.endsWith("_type")) { if (name.endsWith("_type")) {
var vname = name.substring(0, 5); // len("_type")==5 var val = lookupFlow0(flow, prefix);
var val = lookupFlow0(env, vname);
if (val) { if (val) {
return val.type; return val.type;
} }
} }
else if (name.endsWith("_info")) { else if (name.endsWith("_info")) {
var vname = name.substring(0, 5); // len("_info")==5 var val = lookupFlow0(flow, prefix);
var val = lookupFlow0(env, vname);
if (val) { if (val) {
return val.info; return val.info;
} }
} }
else { else {
var val = lookupFlow0(env, name); var val = lookupFlow0(flow, name);
if (val) { if (val) {
return val.value; return val.value;
} }
@ -252,9 +250,9 @@ class Subflow extends Flow {
if (node) { if (node) {
var flow = node._flow; var flow = node._flow;
if (flow) { if (flow) {
var v = lookupFlow(flow, name); var val = lookupFlow(flow, name);
if (v) { if (val) {
return v; return val;
} }
} }
} }

View File

@ -182,7 +182,8 @@ describe('Subflow', function() {
this.received = null; this.received = null;
currentNodes[node.id] = node; currentNodes[node.id] = node;
this.on('input',function(msg) { this.on('input',function(msg) {
var val = node.getenv("__KEY__"); var flow = node._flow;
var val = flow.getSetting("__KEY__");
node.received = val; node.received = val;
node.send({payload: val}); node.send({payload: val});
}); });
@ -566,6 +567,19 @@ describe('Subflow', function() {
}); });
describe("#env var", function() { describe("#env var", function() {
function setEnv(node, key, val) {
var flow = node._flow;
if (flow) {
var sfi = flow.subflowInstance;
sfi.env = [
{
name: key,
value: val
}
];
}
}
it("can access process env var", function(done) { it("can access process env var", function(done) {
var config = flowUtils.parseConfig([ var config = flowUtils.parseConfig([
{id:"t1",type:"tab"}, {id:"t1",type:"tab"},
@ -623,7 +637,7 @@ describe('Subflow', function() {
} }
} }
process.env["__KEY__"] = "__VAL0__"; process.env["__KEY__"] = "__VAL0__";
testenv_node.setenv("__KEY__", "__VAL1__"); setEnv(testenv_node, "__KEY__", "__VAL1__");
currentNodes["1"].receive({payload: "test"}); currentNodes["1"].receive({payload: "test"});
currentNodes["3"].should.have.a.property("received", "__VAL1__"); currentNodes["3"].should.have.a.property("received", "__VAL1__");
@ -674,11 +688,11 @@ describe('Subflow', function() {
currentNodes["1"].receive({payload: "test"}); currentNodes["1"].receive({payload: "test"});
currentNodes["3"].should.have.a.property("received", "__VAL0__"); currentNodes["3"].should.have.a.property("received", "__VAL0__");
node_sf1_1.setenv("__KEY__", "__VAL1__"); setEnv(node_sf1_1, "__KEY__", "__VAL1__");
currentNodes["1"].receive({payload: "test"}); currentNodes["1"].receive({payload: "test"});
currentNodes["3"].should.have.a.property("received", "__VAL1__"); currentNodes["3"].should.have.a.property("received", "__VAL1__");
node_sf2_1.setenv("__KEY__", "__VAL2__"); setEnv(node_sf2_1, "__KEY__", "__VAL2__");
currentNodes["1"].receive({payload: "test"}); currentNodes["1"].receive({payload: "test"});
currentNodes["3"].should.have.a.property("received", "__VAL2__"); currentNodes["3"].should.have.a.property("received", "__VAL2__");