balena-cli/tests/utils/mock.coffee

32 lines
688 B
CoffeeScript
Raw Normal View History

2014-11-14 19:48:37 +00:00
mockFs = require('mock-fs')
sinon = require('sinon')
2014-11-26 17:42:05 +00:00
resin = require('../../lib/resin')
connection = require('../../lib/connection/connection')
2014-11-14 19:48:37 +00:00
exports.fs =
init: (filesystemConfig = {}) ->
mockFsOptions = {}
# Mock data prefix automatically to remove
# duplication in most of the tests
2014-12-05 15:49:00 +00:00
mockFsOptions[resin.settings.get('dataPrefix')] = mockFs.directory()
2014-11-14 19:48:37 +00:00
for key, value of filesystemConfig
mockFsOptions[value.name] = value.contents
mockFs(mockFsOptions)
restore: ->
mockFs.restore()
isOnlineStub = null
exports.connection =
init: ->
isOnlineStub = sinon.stub(connection, 'isOnline')
isOnlineStub.yields(null, true)
restore: ->
isOnlineStub.restore()