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

Third output from Exec node must be consistent for success/failure conditions

This commit is contained in:
Nick O'Leary 2017-03-02 13:34:01 +00:00
parent 54ee655472
commit d8720ee325
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 117 additions and 46 deletions

View File

@ -106,14 +106,16 @@ module.exports = function(RED) {
if(stderr) {
msg2 = {payload: stderr};
}
var msg3 = {payload:0};
var msg3 = null;
node.status({});
//console.log('[exec] stdout: ' + stdout);
//console.log('[exec] stderr: ' + stderr);
if (error !== null) {
msg3 = {payload:error.code};
msg3 = {payload:error};
node.status({fill:"red",shape:"dot",text:"error: "+error.code});
//console.log('[exec] error: ' + error);
} else {
msg3 = {payload: { code: 0 }}
}
node.send([msg,msg2,msg3]);
if (child.tout) { clearTimeout(child.tout); }

View File

@ -64,10 +64,10 @@ describe('exec node', function() {
var n3 = helper.getNode("n3");
var n4 = helper.getNode("n4");
var received = 0;
var messages = [null,null];
var messages = [null,null,null];
var completeTest = function() {
received++;
if (received < 2) {
if (received < 3) {
return;
}
try{
@ -80,6 +80,11 @@ describe('exec node', function() {
msg.should.have.property("payload");
msg.payload.should.be.a.String,
msg.payload.should.equal("ECHO");
msg = messages[2];
msg.should.have.property("payload");
msg.payload.should.have.property("code",0);
child_process.exec.restore();
done();
} catch(err) {
@ -95,6 +100,10 @@ describe('exec node', function() {
messages[1] = msg;
completeTest();
});
n4.on("input", function(msg) {
messages[2] = msg;
completeTest();
});
n1.receive({payload:"and"});
});
});
@ -210,6 +219,68 @@ describe('exec node', function() {
n1.receive({});
});
});
it('should return the rc for a failing command', function(done) {
var flow = [{id:"n1",type:"exec",wires:[["n2"],["n3"],["n4"]],command:"error", addpay:false, append:""},
{id:"n2", type:"helper"},{id:"n3", type:"helper"},{id:"n4", type:"helper"}];
var spy = sinon.stub(child_process, 'exec',
function(arg1,arg2,arg3,arg4) {
//console.log(arg1);
// arg3(error,stdout,stderr);
arg3({code: 1},arg1,arg1.toUpperCase());
});
helper.load(execNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var n3 = helper.getNode("n3");
var n4 = helper.getNode("n4");
var received = 0;
var messages = [null,null,null];
var completeTest = function() {
received++;
if (received < 3) {
return;
}
try{
var msg = messages[0];
msg.should.have.property("payload");
msg.payload.should.be.a.String();
msg.payload.should.equal("error");
msg = messages[1];
msg.should.have.property("payload");
msg.payload.should.be.a.String,
msg.payload.should.equal("ERROR");
msg = messages[2];
msg.should.have.property("payload");
msg.payload.should.have.property("code",1);
child_process.exec.restore();
done();
} catch(err) {
child_process.exec.restore();
done(err);
}
};
n2.on("input", function(msg) {
messages[0] = msg;
completeTest();
});
n3.on("input", function(msg) {
messages[1] = msg;
completeTest();
});
n4.on("input", function(msg) {
messages[2] = msg;
completeTest();
});
n1.receive({payload:"and"});
});
});
});
describe('calling spawn', function() {
@ -367,9 +438,7 @@ describe('exec node', function() {
msg.payload.should.equal("mkdir: /foo/bar/doo: No such file or directory\n");
});
n4.on("input", function(msg) {
msg.should.have.property("payload");
msg.payload.should.be.a.Number();
msg.payload.should.equal(1);
msg.should.have.property("payload",1);
done();
});
n1.receive({payload:null});