Permalink
Browse files

Convert tests to mocha

  • Loading branch information...
wdavidw committed Feb 18, 2012
1 parent 0cc2bfc commit 45906d6cbdb825e4e2e06fce5978f4e211a52286
View
@@ -1,19 +1,29 @@
{
"name": "sigar",
+ "description": "Sigar binding for Node.js",
+ "keywords": ["cluster", "system", "cpu", "os", "network"],
"version": "0.0.1",
- "description": "Sigar binding",
+ "homepage": "http://www.adaltas.com/projects/node-mecano/",
"author": "David Worms <david@adaltas.com>",
- "contributors": [{
- "name": "David Worms",
- "email": "david@adaltas.com"
- }],
- "engines": { "node": ">= 0.6" },
- "bugs": {
- "url": "https://github.com/wdavidw/node-sigar/issues"
- },
"repository": {
"type": "git",
"url": "https://github.com/wdavidw/node-sigar.git"
},
- "homepage": "https://github.com/wdavidw/node-sigar"
+ "bugs": {
+ "email": "open@adaltas.com",
+ "url": "https://github.com/wdavidw/node-sigar.git"
+ },
+ "dependencies": {},
+ "devDependencies": {
+ "mocha": "latest",
+ "should": "latest"
+ },
+ "contributors": [
+ { "name": "David Worms", "email": "david@adaltas.com" }
+ ],
+ "main": "index",
+ "engines": { "node": ">= 0.6.0" },
+ "scripts": {
+ "test": "mocha"
+ }
}
View
@@ -2,5 +2,5 @@ var sigar = require('sigar');
var cpus = sigar().cpuList()
for(var i = 0; i < cpus.length; i++){
- console.log(cpus[i]);
+ console.log(cpus[i]);
}
View
@@ -1,11 +0,0 @@
-
-assert = require 'assert'
-sigar = require '..'
-
-module.exports =
- 'Test formatSize': (next) ->
- s = sigar()
- formatSize = s.formatSize 8492389262
- # console.log 'formatSize', formatSize
- assert.eql formatSize, '7.9G'
- next()
@@ -1,31 +1,30 @@
-assert = require 'assert'
+should = require 'should'
sigar = require '..'
-module.exports =
- 'Test cpu': (next) ->
- s = sigar()
+describe 'cpu', ->
+
+ s = sigar()
+
+ it 'should return overall cpu usage', ->
cpu = s.cpu()
# console.log 'cpu', cpu
- assert.eql [
+ Object.keys(cpu).should.eql [
'user', 'sys', 'nice', 'idle', 'wait', 'irq', 'soft_irq', 'stolen', 'total'
- ], Object.keys(cpu)
- next()
- 'Test cpuList': (next) ->
- s = sigar()
+ ]
+
+ it 'should list cpu with current usage', ->
cpuList = s.cpuList()
# console.log 'cpuList', cpuList
- assert.ok cpuList.length > 0
- assert.eql [
+ cpuList.length.should.be.above 0
+ Object.keys(cpuList[0]).should.eql [
'user', 'sys', 'nice', 'idle', 'wait', 'irq', 'soft_irq', 'stolen', 'total'
- ], Object.keys(cpuList[0])
- next()
- 'Test cpuInfoList': (next) ->
- s = sigar()
+ ]
+
+ it 'should list cpu with information': ->
cpuInfoList = s.cpuInfoList()
# console.log 'cpuInfoList', cpuInfoList
- assert.ok cpuInfoList.length > 0
- assert.eql [
+ cpuList.length.should.be.above 0
+ Object.keys(cpuInfoList[0]).should.eql [
'vendor', 'model', 'mhz', 'mhz_max', 'mhz_min', 'cache_size', 'total_sockets', 'total_cores', 'cores_per_socket'
- ], Object.keys(cpuInfoList[0])
- next()
+ ]
@@ -1,9 +1,12 @@
-assert = require 'assert'
+should = require 'should'
sigar = require '..'
-module.exports =
- 'Test fileSystem constants': (next) ->
+describe 'file_system', ->
+
+ s = sigar()
+
+ it 'should return associated constant code', ->
# console.log 'FSTYPE_UNKNOWN', sigar.FSTYPE_UNKNOWN
# console.log 'FSTYPE_NONE', sigar.FSTYPE_NONE
# console.log 'FSTYPE_LOCAL_DISK', sigar.FSTYPE_LOCAL_DISK
@@ -12,46 +15,42 @@ module.exports =
# console.log 'FSTYPE_CDROM', sigar.FSTYPE_CDROM
# console.log 'FSTYPE_SWAP', sigar.FSTYPE_SWAP
# console.log 'FSTYPE_MAX', sigar.FSTYPE_MAX
- assert.eql sigar.FSTYPE_UNKNOWN, 0
- assert.eql sigar.FSTYPE_NONE, 1
- assert.eql sigar.FSTYPE_LOCAL_DISK, 2
- assert.eql sigar.FSTYPE_NETWORK, 3
- assert.eql sigar.FSTYPE_RAM_DISK, 4
- assert.eql sigar.FSTYPE_CDROM, 5
- assert.eql sigar.FSTYPE_SWAP, 6
- assert.eql sigar.FSTYPE_MAX, 7
- next()
- 'Test fileSystemList': (next) ->
+ sigar.FSTYPE_UNKNOWN.should.eql 0
+ sigar.FSTYPE_NONE.should.eql 1
+ sigar.FSTYPE_LOCAL_DISK.should.eql 2
+ sigar.FSTYPE_NETWORK.should.eql 3
+ sigar.FSTYPE_RAM_DISK.should.eql 4
+ sigar.FSTYPE_CDROM.should.eql 5
+ sigar.FSTYPE_SWAP.should.eql 6
+ sigar.FSTYPE_MAX.should.eql 7
+
+ it 'should return information for each file system', ->
# Note, doesn't seem to be implemented by thread on osx, return rusage of the current thread
- s = sigar()
fileSystemList = s.fileSystemList()
# console.log fileSystemList
for fs in fileSystemList
- if fs.dir_name is '/'
- foundRoot = true
- assert.eql [
- 'dir_name', 'dev_name', 'type_name', 'sys_type_name', 'options', 'type', 'flags'
- ], Object.keys(fs)
- assert.ok foundRoot
- next()
- 'Test fileSystemUsage': (next) ->
+ continue unless fs.dir_name is '/'
+ foundRoot = true
+ Object.keys(fs).should.eql [
+ 'dir_name', 'dev_name', 'type_name', 'sys_type_name', 'options', 'type', 'flags'
+ ],
+ foundRoot.should.be.ok
+
+ it 'should print a file system usage', ->
# Note, doesn't seem to be implemented by thread on osx, return rusage of the current thread
- s = sigar()
fileSystemUsage = s.fileSystemUsage '/'
# console.log 'fileSystemUsage', fileSystemUsage
- assert.eql [
+ Object.keys(fileSystemUsage).should.eql [
'disk', 'use_percent', 'total', 'free', 'used', 'avail', 'files', 'free_files'
- ], Object.keys(fileSystemUsage)
- assert.eql [
+ ]
+ Object.keys(fileSystemUsage.disk).should.eql [
'reads', 'writes', 'write_bytes', 'read_bytes', 'rtime', 'wtime', 'qtime', 'time', 'snaptime', 'service_time', 'queue'
- ], Object.keys(fileSystemUsage.disk)
- next()
- 'Test fileSystemPing': (next) ->
+ ]
+
+ it 'should ping ping the file system', ->
# Note, text decoding is wrong
- s = sigar()
fileSystemPing = s.fileSystemPing()
# console.log fileSystemPing
- assert.eql [
+ Object.keys(fileSystemPing).should.eql [
'dir_name', 'dev_name', 'type_name', 'sys_type_name', 'options', 'type', 'flags'
- ], Object.keys(fileSystemPing)
- next()
+ ]
View
@@ -0,0 +1,12 @@
+
+assert = require 'assert'
+sigar = require '..'
+
+describe 'misc', ->
+
+ s = sigar()
+
+ it 'should output formated size', ->
+ formatSize = s.formatSize 8492389262
+ # console.log 'formatSize', formatSize
+ formatSize.should.eql '7.9G'
Oops, something went wrong.

0 comments on commit 45906d6

Please sign in to comment.