Skip to content

Commit

Permalink
Add basic test for each of udp and tcp server module
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Burry committed Sep 16, 2014
1 parent 42d31f5 commit 8e85af7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/server_tests.js
@@ -0,0 +1,42 @@
var dgram = require('dgram'),
net = require('net');

var config = {
address: '127.0.0.1',
port: 8125
};
var msg = "This is a test\r\n";

module.exports = {
udp_data_received: function(test) {
test.expect(3);
var server = require('../servers/udp');
var started = server.start(config, function(data, rinfo) {
test.equal(msg, data.toString());
test.equal(msg.length, rinfo.size);
test.done();
});
test.ok(started);

var buf = new Buffer(msg);
var sock = dgram.createSocket('udp4');
sock.send(buf, 0, buf.length, config.port, config.address, function(err, bytes) {
sock.close();
});
},
tcp_data_received: function(test) {
test.expect(3);
var server = require('../servers/tcp');
var started = server.start(config, function(data, rinfo) {
test.equal(msg, data.toString());
test.equal(msg.length, rinfo.size);
test.done();
});
test.ok(started);

var client = net.connect(config.port, config.address, function() {
client.write(msg);
client.end();
});
}
}

0 comments on commit 8e85af7

Please sign in to comment.