Permalink
Browse files

Finish up the "test-server-*" test cases.

  • Loading branch information...
1 parent 72d1115 commit 1d77f7e9665f1e6b197b0dc6267065a1148ec299 @TooTallNate committed Jan 5, 2011
Showing with 15 additions and 8 deletions.
  1. +6 −3 test/test-server-with-catchall.js
  2. +9 −5 test/test-server-with-handlers.js
View
9 test/test-server-with-catchall.js
@@ -5,7 +5,7 @@ var assert = require('assert');
exports['server with "catch-all"'] = function() {
var server = s.createServer(function(req, res) {
- console.log(req);
+ //console.log(req);
assert.equal(req.startAddress, 0);
assert.equal(req.quantity, 10);
var rtn = new Array(req.quantity);
@@ -17,8 +17,11 @@ exports['server with "catch-all"'] = function() {
server.listen(PORT, function() {
var conn = require('net').createConnection(PORT);
var clientRequest = new ModbusRequestStack(conn);
- clientRequest.request(4, 0, 10, function(err, clientResponse) {
- console.log(clientResponse);
+ var quantity = 10;
+ clientRequest.request(4, 0, quantity, function(err, clientResponse) {
+ //console.log(clientResponse);
+ assert.ok(Array.isArray(clientResponse));
+ assert.equal(clientResponse.length, quantity);
conn.end();
server.close();
});
View
14 test/test-server-with-handlers.js
@@ -5,10 +5,12 @@ var assert = require('assert');
exports['server with a "handlers" Object'] = function() {
var handlers = {};
+ var startAddress = 0;
+ var quantity = 10;
handlers[4] = function(req, res) {
- console.log(req);
- assert.equal(req.startAddress, 0);
- assert.equal(req.quantity, 10);
+ //console.log(req);
+ assert.equal(req.startAddress, startAddress);
+ assert.equal(req.quantity, quantity);
var rtn = new Array(req.quantity);
for (var i=0; i<req.quantity; i++) {
rtn[i] = req.startAddress + i;
@@ -19,8 +21,10 @@ exports['server with a "handlers" Object'] = function() {
server.listen(PORT, function() {
var conn = require('net').createConnection(PORT);
var clientRequest = new ModbusRequestStack(conn);
- clientRequest.request(4, 0, 10, function(err, clientResponse) {
- console.log(clientResponse);
+ clientRequest.request(4, startAddress, quantity, function(err, clientResponse) {
+ //console.log(clientResponse);
+ assert.ok(Array.isArray(clientResponse));
+ assert.equal(clientResponse.length, quantity);
conn.end();
server.close();
});

0 comments on commit 1d77f7e

Please sign in to comment.