diff --git a/package.json b/package.json index 722f469..67f0825 100644 --- a/package.json +++ b/package.json @@ -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 ", - "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" + } } diff --git a/samples/cpu_list.js b/samples/cpu_list.js index b6a1c51..0bb8777 100644 --- a/samples/cpu_list.js +++ b/samples/cpu_list.js @@ -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]); } diff --git a/test/MiscTest.coffee b/test/MiscTest.coffee deleted file mode 100644 index 70021d6..0000000 --- a/test/MiscTest.coffee +++ /dev/null @@ -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() \ No newline at end of file diff --git a/test/CpuTest.coffee b/test/cpu.coffee similarity index 54% rename from test/CpuTest.coffee rename to test/cpu.coffee index dfe6522..604bfec 100644 --- a/test/CpuTest.coffee +++ b/test/cpu.coffee @@ -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() + ] diff --git a/test/DiskTest.coffee b/test/file_system.coffee similarity index 57% rename from test/DiskTest.coffee rename to test/file_system.coffee index 1429e2c..7e91039 100644 --- a/test/DiskTest.coffee +++ b/test/file_system.coffee @@ -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() \ No newline at end of file + ] diff --git a/test/misc.coffee b/test/misc.coffee new file mode 100644 index 0000000..267d8d9 --- /dev/null +++ b/test/misc.coffee @@ -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' diff --git a/test/NetworkTest.coffee b/test/network.coffee similarity index 55% rename from test/NetworkTest.coffee rename to test/network.coffee index f0ab913..22c5554 100644 --- a/test/NetworkTest.coffee +++ b/test/network.coffee @@ -1,141 +1,143 @@ -assert = require 'assert' +should = require 'should' sigar = require '..' -module.exports = - 'Test netInfo': (next) -> - s = sigar() +describe 'network', -> + + s = sigar() + + it 'should return info', -> netInfo = s.netInfo() # console.log 'netInfo', netInfo - assert.eql [ + Object.keys(netInfo).should.eql [ 'default_gateway', 'default_gateway_interface', 'host_name', 'domain_name', 'primary_dns', 'secondary_dns' - ], Object.keys(netInfo) - next() - 'Test netRouteList': (next) -> - s = sigar() + ] + + it 'should return route list', -> netRouteList = s.netRouteList() - assert.ok netRouteList.length > 0 + netRouteList.length.should.be.above 0 for netRoute in netRouteList # console.log 'netRoute', netRoute - assert.eql [ + Object.keys(netRoute).should.eql [ 'destination', 'gateway', 'mask', 'flags', 'refcnt', 'use', 'metric', 'mtu', 'window', 'irtt', 'ifname' - ], Object.keys(netRoute) - next() - 'Test netInterfaceList': (next) -> - s = sigar() + ] + + it 'should return interface list', -> netInterfaceList = s.netInterfaceList() - assert.ok netInterfaceList.length > 0 + netInterfaceList.length.should.be.above 0 for netInterface in netInterfaceList - assert.ok /^[\w]+$/.test(netInterface) # Note: might be too restricive - next() - 'Test netInterfaceConfig': (next) -> - s = sigar() + /^[\w]+$/.test(netInterface).should.be.ok # Note: might be too restricive + + it 'should return config for a give interface', -> netInterfaceList = s.netInterfaceList() for netInterface in netInterfaceList netInterfaceConfig = s.netInterfaceConfig netInterface - # console.log 'netInterfaceConfig', netInterfaceConfig - next() - 'Test netInterfaceConfigPrimary': (next) -> - s = sigar() + Object.keys(netInterfaceConfig).should.eql [ + 'name', 'type', 'description', 'hwaddr', + 'address', 'destination', 'broadcast', 'netmask', + 'address6', 'prefix6_length', 'scope6', 'flags', + 'mtu', 'metric', 'tx_queue_len' + ] + + it 'should return primary interface configuration', -> netInterfaceConfigPrimary = s.netInterfaceConfigPrimary() # console.log 'netInterfaceConfigPrimary', netInterfaceConfigPrimary - next() - 'Test netInterfaceStat': (next) -> - s = sigar() + Object.keys(netInterfaceConfigPrimary).should.eql [ + 'name', 'type', 'description', 'hwaddr', + 'address', 'destination', 'broadcast', 'netmask', + 'address6', 'prefix6_length', 'scope6', 'flags', + 'mtu', 'metric', 'tx_queue_len' + ] + + it 'should return stat for a given interface', -> netInterfaceList = s.netInterfaceList() for netInterface in netInterfaceList netInterfaceStat = s.netInterfaceStat netInterface # console.log 'netInterfaceStat', netInterface, netInterfaceStat - assert.eql [ + Object.keys(netInterfaceStat).should.eql [ 'rx_packets', 'rx_bytes', 'rx_errors', 'rx_dropped', 'rx_overruns', 'rx_frame', 'tx_packets', 'tx_bytes', 'tx_errors', 'tx_dropped', 'tx_overruns', 'tx_collisions', 'tx_carrier', 'speed' - ], Object.keys(netInterfaceStat) - next() - 'Test netConnectionList': (next) -> - s = sigar() + ] + + it 'should return network connection list', -> netConnectionList = s.netConnectionList -1 - assert.ok netConnectionList.length > 0 + netConnectionList.length.should.be.above 0 for netConnection in netConnectionList # console.log 'netConnection', netConnection - assert.eql [ - 'local_port', 'local_address', 'remote_port', 'remote_address', 'uid', 'inode', 'type', 'state', 'send_queue', 'receive_queue' - ], Object.keys(netConnection) - next() - 'Test netListenAddress': (next) -> - s = sigar() + Object.keys(netConnection).should.eql [ + 'local_port', 'local_address', 'remote_port', + 'remote_address', 'uid', 'inode', 'type', + 'state', 'send_queue', 'receive_queue' + ] + + it 'should return listen address for a give port', -> try netListenAddress = s.netListenAddress 22 # console.log 'netListenAddress', netListenAddress - assert.eql netListenAddress, '0.0.0.0' + netListenAddress.should.eql '0.0.0.0' catch e # SSH port 22 not open - assert.eql e.message, 'sigar_net_listen_address_get error: 2 (No such file or directory)' - next() - 'Test netStat': (next) -> - s = sigar() + e.message.should.eql 'sigar_net_listen_address_get error: 2 (No such file or directory)' + + it 'should return stat', -> netStat = s.netStat -1 # Note, tcp_states are: # SIGAR_TCP_ESTABLISHED = 1, SIGAR_TCP_SYN_SENT, SIGAR_TCP_SYN_RECV, SIGAR_TCP_FIN_WAIT1, # SIGAR_TCP_FIN_WAIT2, SIGAR_TCP_TIME_WAIT, SIGAR_TCP_CLOSE, SIGAR_TCP_CLOSE_WAIT, SIGAR_TCP_LAST_ACK, # SIGAR_TCP_LISTEN, SIGAR_TCP_CLOSING, SIGAR_TCP_IDLE, SIGAR_TCP_BOUND, SIGAR_TCP_UNKNOWN # console.log 'netStat', netStat - assert.eql [ + Object.keys(netStat).should.eql [ 'tcp_states', 'tcp_inbound_total', 'tcp_outbound_total', 'all_inbound_total', 'all_outbound_total' - ], Object.keys(netStat) - assert.eql netStat.tcp_states.length, 14 - next() - 'Test netStatPort': (next) -> - s = sigar() + ] + netStat.tcp_states.length.should.eql 14 + + it 'should return stat for a give port', -> netStatPort = s.netStatPort -1, '127.0.0.1', 22 # console.log 'netStatPort', netStatPort - assert.eql [ + Object.keys(netStatPort).should.eql [ 'tcp_states', 'tcp_inbound_total', 'tcp_outbound_total', 'all_inbound_total', 'all_outbound_total' - ], Object.keys(netStatPort) - assert.eql netStatPort.tcp_states.length, 14 - next() - 'Test tcp': (next) -> - s = sigar() + ] + netStatPort.tcp_states.length.should.eql 14 + + it 'should return tcp info', -> tcp = s.tcp() # console.log 'tcp', tcp - assert.eql [ + Object.keys(tcp).should.eql [ 'active_opens', 'passive_opens', 'attempt_fails', 'estab_resets', 'curr_estab', 'in_segs', 'out_segs', 'retrans_segs', 'in_errs', 'out_rsts' - ], Object.keys(tcp) - next() - 'Test nfsClientV2': (next) -> - s = sigar() + ] + + it 'should return nfsClientV2 info', -> try cpu = s.nfsClientV2() console.log 'nfsClientV2', nfsClientV2 - assert.eql [ + Object.keys(nfsClientV2).should.eql [ 'null', 'getattr', 'setattr', 'root', 'lookup', 'readlink', 'read', 'writecache', 'write', 'create', 'remove', 'rename', 'link', 'symlink', 'mkdir', 'rmdir', 'readdir', 'fsstat' - ], Object.keys(nfsClientV2) + ] catch e # OSX - assert.eql e.message, 'sigar_nfs_client_v2_get error: 20001 (This function has not been implemented on this platform)' - next() - 'Test nfsServerV2': (next) -> - s = sigar() + e.message.should.eql 'sigar_nfs_client_v2_get error: 20001 (This function has not been implemented on this platform)' + + it 'should return nfsServerV2 info', -> try cpu = s.nfsServerV2() console.log 'nfsServerV2', nfsServerV2 - assert.eql [ + Object.keys(nfsServerV2).should.eql [ 'null', 'getattr', 'setattr', 'root', 'lookup', 'readlink', 'read', 'writecache', 'write', 'create', 'remove', 'rename', 'link', 'symlink', 'mkdir', 'rmdir', 'readdir', 'fsstat' - ], Object.keys(nfsServerV2) + ] catch e # OSX - assert.eql e.message, 'sigar_nfs_server_v2_get error: 20001 (This function has not been implemented on this platform)' - next() - 'Test arpList': (next) -> - s = sigar() + e.message.should.eql 'sigar_nfs_server_v2_get error: 20001 (This function has not been implemented on this platform)' + + it 'should list arp', -> arpList = s.arpList() # console.log 'arpList', arpList for arp in arpList - assert.eql [ + Object.keys(arp).should.eql [ 'ifname', 'type', 'hwaddr', 'address', 'flags' - ], Object.keys(arp) - next() + ] + diff --git a/test/ProcessTest.coffee b/test/process.coffee similarity index 62% rename from test/ProcessTest.coffee rename to test/process.coffee index 3d76199..59a7040 100644 --- a/test/ProcessTest.coffee +++ b/test/process.coffee @@ -1,136 +1,125 @@ -assert = require 'assert' +should = require 'should' sigar = require '..' -module.exports = - 'Test procList': (next) -> - s = sigar() +describe 'process', -> + + s = sigar() + + it 'should list all of them', -> procList = s.procList() # console.log 'procList', procList - assert.ok procList.indexOf process.pid isnt -1 - next() - 'Test procStat': (next) -> - s = sigar() + procList.should.include process.pid + + it 'should return statistics info', -> procStat = s.procStat() # console.log 'procStat', procStat - assert.eql [ + Object.keys(procStat).should.eql [ 'total', 'sleeping', 'running', 'zombie', 'stopped', 'idle', 'threads' - ], Object.keys(procStat) - next() - 'Test procMem': (next) -> - s = sigar() + ] + + it 'should return memory info', -> procMem = s.procMem process.pid # console.log 'procMem', procMem - assert.eql [ + Object.keys(procMem).should.eql [ 'size', 'resident', 'share', 'minor_faults', 'major_faults', 'page_faults' - ], Object.keys(procMem) - next() - 'Test procCred': (next) -> - s = sigar() + ] + + it 'should return credential info', -> procCred = s.procCred process.pid # console.log 'procCred', procCred - assert.eql [ + Object.keys(procCred).should.eql [ 'uid', 'gid', 'euid', 'egid' - ], Object.keys(procCred) + ] # procList = s.procList() # for pid in procList # console.log pid, s.procCred pid - next() - 'Test procTime': (next) -> - s = sigar() + + it 'should return time info', -> procTime = s.procTime process.pid # console.log 'procTime', procTime - assert.eql [ + Object.keys(procTime).should.eql [ 'start_time', 'user', 'sys', 'total' - ], Object.keys(procTime) + ] # procList = s.procList() # for pid in procList # console.log pid, s.procTime pid - next() - 'Test procCpu': (next) -> - s = sigar() + + it 'should return cpu info', -> procCpu = s.procCpu process.pid # console.log 'procCpu', procCpu - assert.eql [ + Object.keys(procCpu).should.eql [ 'start_time', 'user', 'sys', 'total', 'last_time', 'percent' - ], Object.keys(procCpu) + ] # procList = s.procList() # for pid in procList # console.log pid, s.procCpu pid - next() - 'Test procState': (next) -> - s = sigar() + + it 'should return state', -> procState = s.procState process.pid # console.log 'procState', procState - assert.eql [ + Object.keys(procState).should.eql [ 'name', 'state', 'ppid', 'tty', 'priority', 'nice', 'processor', 'threads' - ], Object.keys(procState) + ] # procList = s.procList() # for pid in procList # state = s.procState pid # console.log state.name, String.fromCharCode(state.state) # console.log state.name, state.state - next() - 'Test procArgs': (next) -> - s = sigar() + + it 'should return arguments', -> procArgs = s.procArgs process.pid # console.log 'procArgs', procArgs - assert.ok procArgs.length > 0 - assert.eql procArgs[0], 'node' + procArgs.length.should.be.above 0 + procArgs[0].should.eql 'node' # procList = s.procList() # for pid in procList # console.log pid, s.procArgs pid - next() - 'Test procEnv': (next) -> - s = sigar() + + it 'should return environment', -> procEnv = s.procEnv process.pid # console.log 'procEnv', procEnv - assert.eql procEnv['HOME'], process.env['HOME'] - next() - 'Test procFd': (next) -> - s = sigar() + procEnv['HOME'].should.eql process.env['HOME'] + + it 'should return file descriptor', -> try procFd = s.procFd process.pid - console.log 'procFd', procFd - assert.eql [ + # console.log 'procFd', procFd + Object.keys(procFd).should.eql [ 'total' - ], Object.keys(procFd) + ] catch e # OSX - assert.eql e.message, 'sigar_proc_fd_get error: 20001 (This function has not been implemented on this platform)' - next() - 'Test procExe': (next) -> - s = sigar() + e.message.should.eql 'sigar_proc_fd_get error: 20001 (This function has not been implemented on this platform)' + + it 'should return exec information', -> procExe = s.procExe process.pid # console.log 'procExe', procExe - assert.eql [ + Object.keys(procExe).should.eql [ 'name', 'cwd', 'root' - ], Object.keys(procExe) + ] # procList = s.procList() # for pid in procList # console.log pid, s.procExe pid - next() - 'Test procModules': (next) -> - s = sigar() + + it 'should return module information', -> procModules = s.procModules process.pid # console.log 'procModules', procModules - assert.ok Array.isArray procModules - assert.ok procModules.length > 0 + procModules.should.be.instanceof Array + procModules.length.should.be.above 0 # procList = s.procList() # for pid in procList # try # console.log pid, s.procModules pid # catch e # console.log pid, e.message - next() - 'Test procPort': (next) -> - s = sigar() + + it 'should return port information', -> # TODO: start an http server and compare the return pid with the current pid # procPort = s.procPort -1, 4000 # console.log 'procPort', procPort - next() - 'Test threadCpu': (next) -> + + it 'should return cpu usage per thread', -> # Note, doesn't seem to be implemented by thread on osx, return rusage of the current thread - s = sigar() # threadCpu = s.threadCpu process.pid # console.log 'threadCpu', threadCpu # procList = s.procList() @@ -139,4 +128,4 @@ module.exports = # console.log pid, s.threadCpu pid+23 # catch e # console.log pid, e.message - next() + diff --git a/test/SystemTest.coffee b/test/system.coffee similarity index 61% rename from test/SystemTest.coffee rename to test/system.coffee index cab08e6..73afd85 100644 --- a/test/SystemTest.coffee +++ b/test/system.coffee @@ -1,43 +1,41 @@ -assert = require 'assert' +should = require 'should' os = require 'os' sigar = require '..' -module.exports = - 'Test mem': (next) -> - s = sigar() +describe 'system', -> + + s = sigar() + + it 'should return memory', -> mem = s.mem() # console.log 'mem', mem - assert.eql [ + Object.keys(mem).should.eql [ 'ram', 'total', 'used', 'free', 'actual_used', 'actual_free', 'used_percent', 'free_percent' - ], Object.keys(mem) - next() - 'Test swap': (next) -> - s = sigar() + ] + + it 'should return swap', -> swap = s.swap() # console.log 'swap', swap - assert.eql [ + Object.keys(swap).should.eql [ 'total', 'used', 'free','page_in','page_out' - ], Object.keys(swap) - next() - 'Test uptime': (next) -> - s = sigar() + ] + + it 'should return uptime', -> uptime = s.uptime() # console.log 'uptime', uptime - assert.ok uptime > 0 - next() - 'Test loadavg': (next) -> - s = sigar() + uptime.should.be.above 0 + + it 'should return loadavg', -> loadavg = s.loadavg() # console.log 'loadavg', loadavg - assert.eql loadavg.length, 3 - assert.ok loadavg[0] > 0 - next() - 'Test resourceLimit': (next) -> - s = sigar() + loadavg.length.should.eql 3 + loadavg[0].should.be.above 0 + + it 'should resource limit', -> resourceLimit = s.resourceLimit() # console.log 'resourceLimit', resourceLimit - assert.eql [ + Object.keys(resourceLimit).should.eql [ 'cpu_cur', 'cpu_max', 'file_size_cur', 'file_size_max', 'pipe_size_cur', 'pipe_size_max', @@ -48,48 +46,44 @@ module.exports = 'processes_cur', 'processes_max', 'open_files_cur', 'open_files_max', 'virtual_memory_cur', 'virtual_memory_max' - ], Object.keys(resourceLimit) - next() - 'Test whoList': (next) -> - s = sigar() + ] + + it 'should list who', -> whoList = s.whoList() # console.log 'whoList', whoList for who in whoList - assert.eql [ + Object.keys(who).should.eql [ 'user', 'device', 'host', 'time' - ], Object.keys(who) - next() - 'Test version': (next) -> - s = sigar() + ] + + it 'should return version', -> version = s.version() # console.log 'version', version - assert.eql [ + Object.keys(version).should.eql [ 'build_date', 'scm_revision', 'version', 'archname', 'archlib', 'binname', 'description', 'major', 'minor', 'maint', 'build' - ], Object.keys(version) - next() - 'Test sysInfo': (next) -> - s = sigar() + ] + + it 'should return system info', -> sysInfo = s.sysInfo() # console.log 'sysInfo', sysInfo - assert.eql [ + Object.keys(sysInfo).should.eql [ 'name', 'version', 'arch', 'machine', 'description', 'patch_level', 'vendor', 'vendor_version', 'vendor_name', 'vendor_code_name' - ], Object.keys(sysInfo) - next() - 'Test fqdn': (next) -> - s = sigar() + ] + + it 'should return fqdn', -> fqdn = s.fqdn() # console.log 'fqdn', fqdn - assert.ok fqdn is os.hostname() or /^\d+\.\d+\.\d+\.\d+$/.test fqdn - next() + ( os.hostname() or /^\d+\.\d+\.\d+\.\d+$/.test fqdn ).should.be.ok + diff --git a/test/TodoTest.coffee b/test/todo.coffee similarity index 55% rename from test/TodoTest.coffee rename to test/todo.coffee index f1ffd3a..5ba992a 100644 --- a/test/TodoTest.coffee +++ b/test/todo.coffee @@ -1,21 +1,21 @@ -assert = require 'assert' +should = require 'should' sigar = require '..' -module.exports = - 'Test testNetAdress': (next) -> - s = sigar() +describe 'todo', -> + + s = sigar() + + it 'should return net adress', -> testNetAdress = s.testNetAdress '127.0.0.1' # console.log testNetAdress # assert.eql testNetAdress, '127.0.0.1' - next() - 'Test rpcPing': (next) -> - s = sigar() + + it 'should ping rpc', -> # rpcPing = s.rpcPing '127.0.0.1', 0x10, 2 # console.log 'rpcPing', rpcPing - next() - # 'Test password': (next) -> + + # it 'Test password', -> # s = sigar() # password = s.password 'Password please' - # console.log 'password', password - # next() \ No newline at end of file + # console.log 'password', password \ No newline at end of file