balena-supervisor/test/12-logger.spec.coffee
Pablo Carranza Velez 652b596c80 Add some more unit tests to the multicontainer supervisor
We add a bunch of additional unit tests, and also a coverage report using istanbul.

The tests are not meant to cover everything, but they're a first attempt at having *some* unit testing
on the supervisor. There's much to improve but hopefully it helps catch obvious errors.

Change-Type: patch
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
2018-04-30 19:39:01 -07:00

40 lines
1.2 KiB
CoffeeScript

m = require 'mochainon'
{ expect } = m.chai
{ spy, useFakeTimers } = m.sinon
Logger = require '../src/logger'
describe 'Logger', ->
before ->
@fakeBinder = {
logBatch: spy()
}
@fakeEventTracker = {
track: spy()
}
@logger = new Logger({ eventTracker: @fakeEventTracker })
@logger.init({ pubnub: {}, channel: 'foo', offlineMode: 'false', enable: 'true', nativeLogger: 'true', apiBinder: @fakeBinder })
after ->
@logger.stop()
it 'publishes logs to the resin API by default', (done) ->
theTime = Date.now()
@logger.log(message: 'Hello!', timestamp: theTime)
setTimeout( =>
expect(@fakeBinder.logBatch).to.be.calledWith([ { message: 'Hello!', timestamp: theTime } ])
@fakeBinder.logBatch.reset()
done()
, 1020)
it 'allows logging system messages which are also reported to the eventTracker', (done) ->
clock = useFakeTimers()
clock.tick(10)
@logger.logSystemMessage('Hello there!', { someProp: 'someVal' }, 'Some event name')
clock.restore()
setTimeout( =>
expect(@fakeBinder.logBatch).to.be.calledWith([ { message: 'Hello there!', timestamp: 10, isSystem: true } ])
expect(@fakeEventTracker.track).to.be.calledWith('Some event name', { someProp: 'someVal' })
done()
, 1020)