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

Fix UDP in test

This commit is contained in:
Dave Conway-Jones 2018-10-29 22:23:03 +00:00
parent d0bf4a5329
commit 8dba0dac9e
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4

View File

@ -38,8 +38,8 @@ describe('UDP out Node', function() {
function recvData(data, done) { function recvData(data, done) {
var sock = dgram.createSocket('udp4'); var sock = dgram.createSocket('udp4');
sock.on('message', function(msg, rinfo) { sock.on('message', function(msg, rinfo) {
msg.should.deepEqual(data);
sock.close(done); sock.close(done);
msg.should.deepEqual(data);
}); });
sock.bind(port, '127.0.0.1'); sock.bind(port, '127.0.0.1');
port++; port++;
@ -50,37 +50,39 @@ describe('UDP out Node', function() {
var dst_port = dest_in_msg ? undefined : port; var dst_port = dest_in_msg ? undefined : port;
var flow = [{id:"n1", type:"udp out", var flow = [{id:"n1", type:"udp out",
addr:dst_ip, port:dst_port, iface: "", addr:dst_ip, port:dst_port, iface: "",
ipv:proto, outport: "random", ipv:proto, outport: "",
base64:decode, multicast:false, base64:decode, multicast:false,
wires:[] }]; wires:[] }];
helper.load(udpNode, flow, function() { helper.load(udpNode, flow, function() {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
var msg = {}; var msg = {};
if(decode) { if (decode) {
msg.payload = Buffer("hello").toString('base64'); msg.payload = Buffer.from("hello").toString('base64');
} }
else { else {
msg.payload = "hello"; msg.payload = "hello";
} }
if(dest_in_msg) { if (dest_in_msg) {
msg.ip = "127.0.0.1"; msg.ip = "127.0.0.1";
msg.port = port; msg.port = port;
} }
recvData(val1, done); recvData(val1, done);
setTimeout(function() {
n1.receive(msg); n1.receive(msg);
}, 200);
}); });
} }
it('should send IPv4 data', function(done) { it('should send IPv4 data', function(done) {
checkSend('udp4', 'hello', Buffer('hello'), false, false, done); checkSend('udp4', 'hello', Buffer.from('hello'), false, false, done);
}); });
it('should send IPv4 data (base64)', function(done) { it('should send IPv4 data (base64)', function(done) {
checkSend('udp4', 'hello', Buffer('hello'), true, false, done); checkSend('udp4', 'hello', Buffer.from('hello'), true, false, done);
}); });
it('should send IPv4 data with dest from msg', function(done) { it('should send IPv4 data with dest from msg', function(done) {
checkSend('udp4', 'hello', Buffer('hello'), false, true, done); checkSend('udp4', 'hello', Buffer.from('hello'), false, true, done);
}); });
}); });