mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
fix and test
This commit is contained in:
parent
e5f1029d0c
commit
02bd292b8c
@ -517,6 +517,7 @@ module.exports = function(RED) {
|
|||||||
this.port = Number(n.port);
|
this.port = Number(n.port);
|
||||||
this.out = n.out;
|
this.out = n.out;
|
||||||
this.ret = n.ret || "buffer";
|
this.ret = n.ret || "buffer";
|
||||||
|
this.newline = n.newline;
|
||||||
this.splitc = n.splitc;
|
this.splitc = n.splitc;
|
||||||
if (n.tls) {
|
if (n.tls) {
|
||||||
var tlsNode = RED.nodes.getNode(n.tls);
|
var tlsNode = RED.nodes.getNode(n.tls);
|
||||||
|
@ -84,10 +84,18 @@ describe('TCP Request Node', function() {
|
|||||||
n2.on("input", msg => {
|
n2.on("input", msg => {
|
||||||
try {
|
try {
|
||||||
if (typeof result === 'object') {
|
if (typeof result === 'object') {
|
||||||
|
if (flow[0].ret === "string") {
|
||||||
|
msg.should.have.properties(Object.assign({}, result, {payload: result.payload}));
|
||||||
|
} else {
|
||||||
msg.should.have.properties(Object.assign({}, result, {payload: Buffer.from(result.payload)}));
|
msg.should.have.properties(Object.assign({}, result, {payload: Buffer.from(result.payload)}));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (flow[0].ret === "string") {
|
||||||
|
msg.should.have.property('payload', result);
|
||||||
} else {
|
} else {
|
||||||
msg.should.have.property('payload', Buffer.from(result));
|
msg.should.have.property('payload', Buffer.from(result));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
done();
|
done();
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
done(err);
|
done(err);
|
||||||
@ -245,10 +253,23 @@ describe('TCP Request Node', function() {
|
|||||||
}, done);
|
}, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should send & receive, then keep connection, and split return strings', function(done) {
|
||||||
|
var flow = [{id:"n1", type:"tcp request", server:"localhost", port:port, out:"sit", ret:"string", newline:"<A>", wires:[["n2"]] },
|
||||||
|
{id:"n2", type:"helper"}];
|
||||||
|
testTCPMany(flow, [{
|
||||||
|
payload: "foo<A>bar",
|
||||||
|
topic: 'boo'
|
||||||
|
}], {
|
||||||
|
payload: "ACK:foo<A>",
|
||||||
|
topic: 'boo'
|
||||||
|
}, done);
|
||||||
|
});
|
||||||
|
|
||||||
it('should send & recv data to/from server:port from msg', function(done) {
|
it('should send & recv data to/from server:port from msg', function(done) {
|
||||||
var flow = [{id:"n1", type:"tcp request", server:"", port:"", out:"time", splitc: "0", wires:[["n2"]] },
|
var flow = [{id:"n1", type:"tcp request", server:"", port:"", out:"time", splitc: "0", wires:[["n2"]] },
|
||||||
{id:"n2", type:"helper"}];
|
{id:"n2", type:"helper"}];
|
||||||
testTCPMany(flow, [{
|
testTCPMany(flow, [
|
||||||
|
{
|
||||||
payload: "f",
|
payload: "f",
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
port: port
|
port: port
|
||||||
|
Loading…
Reference in New Issue
Block a user