mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-18 02:39:49 +00:00
Decouple resin sdk from it's surroundings
This commit is contained in:
parent
07c57d335b
commit
8ac36ced4d
@ -1,5 +1,4 @@
|
||||
_ = require('lodash')
|
||||
isOnline = require('is-online')
|
||||
|
||||
CONNECTION_PARAMETERS = [
|
||||
'network'
|
||||
@ -7,10 +6,6 @@ CONNECTION_PARAMETERS = [
|
||||
'wifiKey'
|
||||
]
|
||||
|
||||
# A wrapper around isOnline in order
|
||||
# to be able to stub it with Sinon
|
||||
exports.isOnline = isOnline
|
||||
|
||||
validateEthernetConnectionParameters = (parameters = {}) ->
|
||||
return if not parameters.wifiSsid? and not parameters.wifiKey?
|
||||
return new Error('You can only use wifi options if network is wifi')
|
||||
|
@ -5,37 +5,6 @@ connection = require('./connection')
|
||||
|
||||
describe 'Connection:', ->
|
||||
|
||||
describe '#isOnline()', ->
|
||||
|
||||
stubIsOnline = (expectations, args...) ->
|
||||
isOnlineStub = sinon.stub(connection, 'isOnline')
|
||||
isOnlineStub.yields(args...)
|
||||
|
||||
connection.isOnline (error, isOnline) ->
|
||||
expectations.apply(null, arguments)
|
||||
isOnlineStub.restore()
|
||||
|
||||
it 'should be able to return true', (done) ->
|
||||
stubIsOnline (error, isOnline) ->
|
||||
expect(error).to.not.exist
|
||||
expect(isOnline).to.be.true
|
||||
done()
|
||||
, null, true
|
||||
|
||||
it 'should be able to return false', (done) ->
|
||||
stubIsOnline (error, isOnline) ->
|
||||
expect(error).to.not.exist
|
||||
expect(isOnline).to.be.false
|
||||
done()
|
||||
, null, false
|
||||
|
||||
it 'should be able to return an error', (done) ->
|
||||
stubIsOnline (error, isOnline) ->
|
||||
expect(error).to.be.an.instanceof(Error)
|
||||
expect(isOnline).to.not.exist
|
||||
done()
|
||||
, new Error()
|
||||
|
||||
describe '#parseConnectionParameters()', ->
|
||||
|
||||
checkParamsSuccess = (params, done) ->
|
||||
|
3
lib/resin/_connection/connection.coffee
Normal file
3
lib/resin/_connection/connection.coffee
Normal file
@ -0,0 +1,3 @@
|
||||
# A wrapper around isOnline in order
|
||||
# to be able to stub it with Sinon
|
||||
exports.isOnline = require('is-online')
|
37
lib/resin/_connection/connection.spec.coffee
Normal file
37
lib/resin/_connection/connection.spec.coffee
Normal file
@ -0,0 +1,37 @@
|
||||
expect = require('chai').expect
|
||||
_ = require('lodash')
|
||||
sinon = require('sinon')
|
||||
connection = require('./connection')
|
||||
|
||||
describe 'Connection:', ->
|
||||
|
||||
describe '#isOnline()', ->
|
||||
|
||||
stubIsOnline = (expectations, args...) ->
|
||||
isOnlineStub = sinon.stub(connection, 'isOnline')
|
||||
isOnlineStub.yields(args...)
|
||||
|
||||
connection.isOnline (error, isOnline) ->
|
||||
expectations.apply(null, arguments)
|
||||
isOnlineStub.restore()
|
||||
|
||||
it 'should be able to return true', (done) ->
|
||||
stubIsOnline (error, isOnline) ->
|
||||
expect(error).to.not.exist
|
||||
expect(isOnline).to.be.true
|
||||
done()
|
||||
, null, true
|
||||
|
||||
it 'should be able to return false', (done) ->
|
||||
stubIsOnline (error, isOnline) ->
|
||||
expect(error).to.not.exist
|
||||
expect(isOnline).to.be.false
|
||||
done()
|
||||
, null, false
|
||||
|
||||
it 'should be able to return an error', (done) ->
|
||||
stubIsOnline (error, isOnline) ->
|
||||
expect(error).to.be.an.instanceof(Error)
|
||||
expect(isOnline).to.not.exist
|
||||
done()
|
||||
, new Error()
|
@ -2,7 +2,7 @@ _ = require('lodash')
|
||||
request = require('request')
|
||||
progress = require('request-progress')
|
||||
async = require('async')
|
||||
connection = require('../../connection/connection')
|
||||
connection = require('../_connection/connection')
|
||||
settings = require('../settings')
|
||||
auth = require('../auth/auth')
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
mockFs = require('mock-fs')
|
||||
sinon = require('sinon')
|
||||
resin = require('../../lib/resin')
|
||||
connection = require('../../lib/connection/connection')
|
||||
connection = require('../../lib/resin/_connection/connection')
|
||||
|
||||
exports.fs =
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user