mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-28 15:14:34 +00:00
51 lines
1.3 KiB
CoffeeScript
51 lines
1.3 KiB
CoffeeScript
_ = require('lodash')
|
|
chai = require('chai')
|
|
expect = chai.expect
|
|
config = require('./config')
|
|
mock = require('../../../tests/utils/mock')
|
|
|
|
FILESYSTEM =
|
|
config:
|
|
name: 'config'
|
|
contents: JSON.stringify
|
|
directories:
|
|
plugins: 'myPlugins'
|
|
remoteUrl: 'http://localhost:9001'
|
|
directoryConfig:
|
|
name: 'directoryConfig'
|
|
contents: {}
|
|
notJSON:
|
|
name: 'notJSON'
|
|
contents: 'Not JSON content'
|
|
|
|
describe 'Config:', ->
|
|
|
|
beforeEach ->
|
|
mock.fs.init(FILESYSTEM)
|
|
|
|
afterEach ->
|
|
mock.fs.restore()
|
|
|
|
describe '#loadUserConfig()', ->
|
|
|
|
it 'should load the default config file', ->
|
|
configFile = FILESYSTEM.config.name
|
|
result = config.loadUserConfig(configFile)
|
|
expectedContents = JSON.parse(FILESYSTEM.config.contents)
|
|
expect(result).to.deep.equal(expectedContents)
|
|
|
|
it 'should return undefined if config file does not exist', ->
|
|
configFile = 'foobar'
|
|
result = config.loadUserConfig(configFile)
|
|
expect(result).to.be.undefined
|
|
|
|
it 'should throw an error if config file is not a file', ->
|
|
configFile = FILESYSTEM.directoryConfig.name
|
|
func = _.partial(config.loadUserConfig, configFile)
|
|
expect(func).to.throw(Error)
|
|
|
|
it 'should throw an error if config is not a json file', ->
|
|
configFile = FILESYSTEM.notJSON.name
|
|
func = _.partial(config.loadUserConfig, configFile)
|
|
expect(func).to.throw(Error)
|