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

View File

@ -182,7 +182,8 @@ describe('Subflow', function() {
this.received = null;
currentNodes[node.id] = node;
this.on('input',function(msg) {
var val = node.getenv("__KEY__");
var flow = node._flow;
var val = flow.getSetting("__KEY__");
node.received = val;
node.send({payload: val});
});
@ -566,6 +567,19 @@ describe('Subflow', 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) {
var config = flowUtils.parseConfig([
{id:"t1",type:"tab"},
@ -623,7 +637,7 @@ describe('Subflow', function() {
}
}
process.env["__KEY__"] = "__VAL0__";
testenv_node.setenv("__KEY__", "__VAL1__");
setEnv(testenv_node, "__KEY__", "__VAL1__");
currentNodes["1"].receive({payload: "test"});
currentNodes["3"].should.have.a.property("received", "__VAL1__");
@ -674,11 +688,11 @@ describe('Subflow', function() {
currentNodes["1"].receive({payload: "test"});
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["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["3"].should.have.a.property("received", "__VAL2__");