Permalink
Browse files

Moved lib code, added tests for the parsing.

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information...
1 parent 3b37002 commit 61d6b1398c84bbf005c80b1b821109598b5bdd4d @ncb000gt committed Aug 14, 2011
Showing with 86 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 index.js
  3. +3 −3 lib/{index.js → ventstatus.js}
  4. +1 −1 package.json
  5. +78 −0 tests/test-parse.js
View
@@ -0,0 +1 @@
+*.sw[a-z]
View
@@ -0,0 +1,3 @@
+var ventstatus = require('./lib/ventstatus');
+
+module.exports = ventstatus;
@@ -38,9 +38,9 @@ VentStatus.prototype.parseResults = function(err, stdout, stderr, cb) {
}
};
- if (err) return cb(err);
- if (stderr) return cb(stderr);
- if (!stdout) return cb("No data returned");
+ if (err && err.code === 3) return cb("Invalid host:port for ventrilo server.");
+ if (err && err.code === 5) return cb("Invalid code provided.");
+ if (!stdout) return cb("No data returned.");
stdout.split('\n').forEach(function(line) {
var m = line.match(/([^:]*):/);
View
@@ -1,7 +1,7 @@
{
"name": "ventstatus",
"description": "Module that uses ventrilo_status to report on the status of a ventrilo server",
- "main": "./lib/index",
+ "main": "./index",
"version": "0.0.1",
"engine": { "node": ">=0.4.0" },
"author": "Nick Campbell (https://github.com/ncb000gt)",
View
@@ -0,0 +1,78 @@
+var testCase = require('nodeunit').testCase;
+
+var FAKE_VENT_CONFIG = {
+ cmd: "ventrilo_status",
+ host: "localhost",
+ port: "50000"
+};
+var ventstatus = require("../index")(FAKE_VENT_CONFIG);
+
+var VENT_TEST_DATA = {
+ info: {
+ name: "Test Vent Server",
+ phonetic: "test vent server",
+ comment: "test vent server comment",
+ auth: "1",
+ maxclients: "10",
+ voicecodec: "3,Speex",
+ voiceformat: "32,32 KHz%2C 16 bit%2C 10 Qlty",
+ uptime: "10",
+ platform: "WIN32",
+ version: "3.0.3.C"
+ },
+ channels: [
+ "Test Channel 1",
+ "Test Channel 2"
+ ],
+ clients: [
+ "TestUser1",
+ "TestUser2"
+ ]
+};
+var FULL_DATA = "NAME: "+ VENT_TEST_DATA.info.name +"\n" +
+ "PHONETIC: "+ VENT_TEST_DATA.info.phonetic +"\n" +
+ "COMMENT: "+ VENT_TEST_DATA.info.comment+"\n" +
+ "AUTH: "+ VENT_TEST_DATA.info.auth +"\n" +
+ "MAXCLIENTS: "+ VENT_TEST_DATA.info.maxclients+"\n" +
+ "VOICECODEC: "+ VENT_TEST_DATA.info.voicecodec +"\n" +
+ "VOICEFORMAT: "+ VENT_TEST_DATA.info.voiceformat +"\n" +
+ "UPTIME: "+ VENT_TEST_DATA.info.uptime +"\n" +
+ "PLATFORM: "+ VENT_TEST_DATA.info.platform +"\n" +
+ "VERSION: "+ VENT_TEST_DATA.info.version +"\n" +
+ "CHANNELCOUNT: 2\n" +
+ "CHANNELFIELDS: CID,PID,PROT,NAME,COMM\n" +
+ "CHANNEL: CID=632,PID=0,PROT=0,NAME="+ VENT_TEST_DATA.channels[0] +",COMM=\n" +
+ "CHANNEL: CID=633,PID=0,PROT=0,NAME="+ VENT_TEST_DATA.channels[1] +",COMM=\n" +
+ "CLIENTCOUNT: 2\n" +
+ "CLIENTFIELDS: ADMIN,CID,PHAN,PING,SEC,NAME,COMM\n" +
+ "CLIENT: ADMIN=0,CID=632,PHAN=0,PING=46,SEC=2294,NAME="+ VENT_TEST_DATA.clients[0] +",COMM=\n" +
+ "CLIENT: ADMIN=0,CID=632,PHAN=0,PING=93,SEC=2263,NAME="+ VENT_TEST_DATA.clients[1] +",COMM=";
+
+module.exports = testCase({
+ "parse full data": function(assert) {
+ assert.expect(14);
+ ventstatus.parseResults(null, FULL_DATA, null, function(err, data) {
+ for (var p in data.info) {
+ assert.equal(data.info[p], VENT_TEST_DATA.info[p]);
+ }
+
+ for (var i = 0; i < data.channels.length; i++) {
+ assert.equal(data.channels[i], VENT_TEST_DATA.channels[i]);
+ }
+
+ for (var i = 0; i < data.clients.length; i++) {
+ assert.equal(data.clients[i], VENT_TEST_DATA.clients[i]);
+ }
+
+ assert.done();
+ });
+
+ },
+ "parse empty data": function(assert) {
+ assert.expect(1);
+ ventstatus.parseResults(null, "", null, function(err, data) {
+ assert.equal(err, "No data returned.");
+ assert.done();
+ });
+ }
+});

0 comments on commit 61d6b13

Please sign in to comment.