Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add vows tests

  • Loading branch information...
commit 41451ecdff7639c9f997827d1f0daea208e18bcd 1 parent 5e66705
@mzsanford mzsanford authored
View
2  .gitignore
@@ -0,0 +1,2 @@
+node_modules/
+npm-debug.log
View
6 package.json
@@ -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
29 test/counters.js
@@ -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
42 test/raw.js
@@ -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
55 test/raw_tcp.js
@@ -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 });
Please sign in to comment.
Something went wrong with that request. Please try again.