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

Add tail node binary mode test

This commit is contained in:
Dave Conway-Jones 2016-02-25 08:52:43 +00:00
parent d3a98dd355
commit 0d1543ee8a
2 changed files with 20 additions and 2 deletions

View File

@ -28,7 +28,7 @@ module.exports = function(RED) {
this.filename = n.filename; this.filename = n.filename;
this.filetype = n.filetype || "text"; this.filetype = n.filetype || "text";
this.split = n.split; this.split = n.split || false;
var node = this; var node = this;
var err = ""; var err = "";
@ -36,7 +36,7 @@ module.exports = function(RED) {
var tail = spawn("tail", ["-F", "-n", "0", this.filename]); var tail = spawn("tail", ["-F", "-n", "0", this.filename]);
tail.stdout.on("data", function (data) { tail.stdout.on("data", function (data) {
var msg = { topic:node.filename }; var msg = { topic:node.filename };
if (this.filetype === "text") { if (node.filetype === "text") {
if (node.split) { if (node.split) {
// TODO: allow customisation of the line break - as we do elsewhere // TODO: allow customisation of the line break - as we do elsewhere
var strings = data.toString().split("\n"); var strings = data.toString().split("\n");

View File

@ -88,6 +88,24 @@ describe('tail Node', function() {
}); });
}); });
it('should work in binary mode', function(done) {
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "filetype":"binary", "filename":fileToTail, "wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
helper.load(tailNode, flow, function() {
var tailNode1 = helper.getNode("tailNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
//console.log(msg);
msg.should.have.property('topic', fileToTail);
msg.payload.toString().should.equal("Tail message line 7\nTail message line 8\n");
done();
});
setTimeout( function() {
fs.appendFileSync(fileToTail, "Tail message line 7\nTail message line 8\n");
},wait);
});
});
it('should handle a non-existent file', function(done) { it('should handle a non-existent file', function(done) {
fs.writeFileSync(fileToTail, "Tail message line.\n"); fs.writeFileSync(fileToTail, "Tail message line.\n");
var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail, "wires":[["helperNode1"]]}, var flow = [{id:"tailNode1", type:"tail", name: "tailNode", "split":true, "filename":fileToTail, "wires":[["helperNode1"]]},