2014-02-18 21:34:36 +00:00
|
|
|
path = require 'path'
|
|
|
|
|
fs = require 'fs'
|
2014-04-02 13:54:20 +00:00
|
|
|
stdPath = path.resolve __dirname, '..', 'logs', 'server.log'
|
2014-04-05 01:09:40 +00:00
|
|
|
logger = require path.join '..', 'js', 'logging'
|
2014-02-18 21:34:36 +00:00
|
|
|
|
|
|
|
|
getLog = ( strPath, cb ) ->
|
2014-04-16 15:42:56 +00:00
|
|
|
fWait = ->
|
|
|
|
|
# cb fs.readFileSync path, 'utf-8'
|
|
|
|
|
str = fs.readFileSync path.resolve( strPath ), 'utf-8'
|
|
|
|
|
arrStr = str.split "\n"
|
|
|
|
|
fConvertRow = ( row ) ->
|
|
|
|
|
try
|
|
|
|
|
JSON.parse row
|
|
|
|
|
arrStr[i] = fConvertRow row for row, i in arrStr
|
|
|
|
|
cb arrStr.slice 0, arrStr.length - 1
|
|
|
|
|
setTimeout fWait, 100
|
2014-02-17 22:27:26 +00:00
|
|
|
|
2014-04-02 13:54:20 +00:00
|
|
|
exports.setUp = ( cb ) ->
|
2014-04-16 15:42:56 +00:00
|
|
|
try
|
|
|
|
|
fs.unlinkSync stdPath
|
|
|
|
|
cb()
|
2014-02-17 22:27:26 +00:00
|
|
|
|
2014-04-02 13:54:20 +00:00
|
|
|
exports.testCreate = ( test ) ->
|
2014-04-16 15:42:56 +00:00
|
|
|
test.expect 2
|
|
|
|
|
arrLogs = [
|
|
|
|
|
'TL | testInitIO - info'
|
|
|
|
|
'TL | testInitIO - warn'
|
|
|
|
|
'TL | testInitIO - error'
|
|
|
|
|
]
|
|
|
|
|
args = {}
|
|
|
|
|
args[ 'io-level' ] = 'error'
|
|
|
|
|
log = logger.getLogger args
|
|
|
|
|
log.info arrLogs[0]
|
|
|
|
|
log.warn arrLogs[1]
|
|
|
|
|
log.error arrLogs[2]
|
|
|
|
|
test.ok fs.existsSync( stdPath ), 'Log file does not exist!'
|
|
|
|
|
getLog stdPath, ( arr ) ->
|
|
|
|
|
allCorrect = true
|
|
|
|
|
for o,i in arr
|
|
|
|
|
if o.msg is not arrLogs[i]
|
|
|
|
|
allCorrect = false
|
|
|
|
|
test.ok allCorrect, 'Log file does not contain the correct entries!'
|
|
|
|
|
test.done()
|
2014-02-18 21:34:36 +00:00
|
|
|
|
2014-04-02 13:54:20 +00:00
|
|
|
exports.testNoLog = ( test ) ->
|
2014-04-16 15:42:56 +00:00
|
|
|
test.expect 1
|
2014-02-17 22:27:26 +00:00
|
|
|
|
2014-04-16 15:42:56 +00:00
|
|
|
log = logger.getLogger
|
|
|
|
|
nolog: true
|
|
|
|
|
log.info 'TL | test 1'
|
2014-02-17 22:27:26 +00:00
|
|
|
|
2014-04-16 15:42:56 +00:00
|
|
|
fWait = () ->
|
|
|
|
|
test.ok !fs.existsSync( stdPath ), 'Log file does still exist!'
|
|
|
|
|
test.done()
|
2014-02-17 22:27:26 +00:00
|
|
|
|
2014-04-16 15:42:56 +00:00
|
|
|
setTimeout fWait, 100
|
2014-02-17 22:27:26 +00:00
|
|
|
|
2014-04-02 13:54:20 +00:00
|
|
|
exports.testCustomPath = ( test ) ->
|
2014-04-16 15:42:56 +00:00
|
|
|
test.expect 2
|
2014-02-17 22:27:26 +00:00
|
|
|
|
2014-04-16 15:42:56 +00:00
|
|
|
strInfo = 'TL | custom path test 1'
|
|
|
|
|
strPath = 'testing/files/test.log'
|
|
|
|
|
args = {}
|
|
|
|
|
args[ 'file-path' ] = strPath
|
|
|
|
|
args[ 'io-level' ] = 'error'
|
2014-02-17 22:27:26 +00:00
|
|
|
|
2014-04-16 15:42:56 +00:00
|
|
|
log = logger.getLogger args
|
|
|
|
|
log.info strInfo
|
2014-02-17 22:27:26 +00:00
|
|
|
|
2014-04-16 15:42:56 +00:00
|
|
|
fWait = () ->
|
|
|
|
|
test.ok fs.existsSync( strPath ), 'Custom log file does not exist!'
|
|
|
|
|
getLog strPath, ( arr ) ->
|
|
|
|
|
test.ok arr[0].msg is strInfo, 'Custom log file not correct!'
|
|
|
|
|
try
|
|
|
|
|
fs.unlinkSync strPath
|
|
|
|
|
test.done()
|
2014-02-18 21:34:36 +00:00
|
|
|
|
2014-04-16 15:42:56 +00:00
|
|
|
setTimeout fWait, 100
|
2014-02-17 22:27:26 +00:00
|
|
|
|
2014-04-02 13:54:20 +00:00
|
|
|
exports.testWrongPath = ( test ) ->
|
2014-04-16 15:42:56 +00:00
|
|
|
empty = [
|
|
|
|
|
'trace'
|
|
|
|
|
'debug'
|
|
|
|
|
'info'
|
|
|
|
|
'warn'
|
|
|
|
|
'error'
|
|
|
|
|
'fatal'
|
|
|
|
|
]
|
|
|
|
|
test.expect empty.length
|
2014-02-18 21:34:36 +00:00
|
|
|
|
2014-04-16 15:42:56 +00:00
|
|
|
strInfo = 'TL | custom path test 1'
|
|
|
|
|
strPath = 'strange/path/to/test.log'
|
|
|
|
|
args = {}
|
|
|
|
|
args[ 'file-path' ] = strPath
|
|
|
|
|
args[ 'io-level' ] = 'error'
|
|
|
|
|
log = logger.getLogger args
|
|
|
|
|
test.ok prop in empty, "#{ prop } shouldn't be here" for prop of log
|
|
|
|
|
test.done()
|
2014-02-17 22:27:26 +00:00
|
|
|
|
2014-04-16 15:42:56 +00:00
|
|
|
|