Permalink
Browse files

Add vows tests

  • Loading branch information...
1 parent 5e66705 commit 41451ecdff7639c9f997827d1f0daea208e18bcd @mzsanford mzsanford committed Jul 23, 2012
Showing with 134 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +6 −0 package.json
  3. +29 −0 test/counters.js
  4. +42 −0 test/raw.js
  5. +55 −0 test/raw_tcp.js
View
@@ -0,0 +1,2 @@
+node_modules/
+npm-debug.log
View
@@ -9,12 +9,18 @@
],
"main": "./lib/lsof",
"engines": { "node": ">= 0.2.0" },
+ "scripts": {
+ "test": "vows --spec test/*"
+ },
"licenses":[
{
"type" : "BSD",
"url" : "https://github.com/davglass/node-lsof/blob/master/LICENSE"
}
],
+ "devDependencies": {
+ "vows": "0.6.x"
+ },
"repository": {
"type":"git",
"url":"http://github.com/davglass/node-lsof.git"
View
@@ -0,0 +1,29 @@
+var vows = require('vows'),
+ assert = require('assert'),
+ lsof = require('../lib/lsof.js');
+
+// Create a Test Suite
+vows.describe('lsof').addBatch({
+ 'counters': {
+ topic: function() {
+ lsof.counters(this.callback);
+ },
+
+ 'contains a pid': function(topic) {
+ assert.isNumber(topic['pid']);
+ assert.equal(process.pid, topic['pid']);
+ },
+ 'contains a user': function(topic) {
+ assert.isString(topic['user']);
+ },
+ 'contains an open count': function(topic) {
+ assert.isNumber(topic['open']);
+ },
+ 'contains a complete types object': function(topic) {
+ assert.isNumber(topic['types']['dir']);
+ assert.isNumber(topic['types']['reg']);
+ assert.isNumber(topic['types']['chr']);
+ assert.isNumber(topic['types']['pipe']);
+ },
+ }
+}).export(module, { error: false });
View
@@ -0,0 +1,42 @@
+var vows = require('vows'),
+ assert = require('assert'),
+ lsof = require('../lib/lsof.js');
+
+// Create a Test Suite
+vows.describe('lsof').addBatch({
+ 'raw': {
+ topic: function() {
+ lsof.raw(this.callback);
+ },
+
+ 'contains key: command': function(topic) {
+ assert.isString(topic[0]['command']);
+ assert.equal('node', topic[0]['command']);
+ },
+ 'contains key: pid': function(topic) {
+ assert.match(topic[0]['pid'], /^[0-9]+$/);
+ assert.equal(process.pid, topic[0]['pid']);
+ },
+ 'contains key: user': function(topic) {
+ assert.isString(topic[0]['user']);
+ },
+ 'contains key: fd': function(topic) {
+ assert.isString(topic[0]['fd']);
+ },
+ 'contains key: type': function(topic) {
+ assert.isString(topic[0]['type']);
+ },
+ 'contains key: device': function(topic) {
+ assert.isString(topic[0]['device']);
+ },
+ 'contains key: size/off': function(topic) {
+ assert.isString(topic[0]['size/off']);
+ },
+ 'contains key: node': function(topic) {
+ assert.isString(topic[0]['node']);
+ },
+ 'contains key: name': function(topic) {
+ assert.isString(topic[0]['name']);
+ }
+ }
+}).export(module, { error: false });
View
@@ -0,0 +1,55 @@
+var vows = require('vows'),
+ assert = require('assert'),
+ lsof = require('../lib/lsof.js'),
+ net = require('net');
+
+// Create a known listening socket
+var testPort = 65478;
+var server = net.createServer(function (socket) {
+ socket.write('Echo server\r\n');
+ socket.pipe(socket);
+});
+server.listen(testPort, '127.0.0.1');
+
+// Create a Test Suite
+vows.describe('lsof').addBatch({
+ 'raw tcp': {
+ topic: function() {
+ lsof.rawTcpPort(testPort, this.callback);
+ },
+
+ 'contains key: command': function(topic) {
+ assert.isString(topic[0]['command']);
+ assert.equal('node', topic[0]['command']);
+ },
+ 'contains key: pid': function(topic) {
+ assert.match(topic[0]['pid'], /^[0-9]+$/);
+ assert.equal(process.pid, topic[0]['pid']);
+ },
+ 'contains key: user': function(topic) {
+ assert.isString(topic[0]['user']);
+ },
+ 'contains key: fd': function(topic) {
+ assert.isString(topic[0]['fd']);
+ },
+ 'contains key: type': function(topic) {
+ assert.isString(topic[0]['type']);
+ },
+ 'contains key: device': function(topic) {
+ assert.isString(topic[0]['device']);
+ },
+ 'contains key: size/off': function(topic) {
+ assert.isString(topic[0]['size/off']);
+ },
+ 'contains key: node': function(topic) {
+ assert.isString(topic[0]['node']);
+ },
+ 'contains key: name': function(topic) {
+ assert.isString(topic[0]['name']);
+ },
+ 'contains the state for a listening socket': function(topic) {
+ assert.isString(topic[0]['state']);
+ assert.equal('listen', topic[0]['state']);
+ }
+ }
+}).export(module, { error: false });

0 comments on commit 41451ec

Please sign in to comment.