mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-03-23 04:25:29 +00:00
Remove unused config module
This commit is contained in:
parent
be08a83765
commit
c4422a171c
@ -1,32 +0,0 @@
|
||||
fs = require('fs')
|
||||
errors = require('../errors/errors')
|
||||
|
||||
# Read JSON configuration file
|
||||
#
|
||||
# @private
|
||||
#
|
||||
# User config loading should be sync, as we need to
|
||||
# extend this module with the result before exporting
|
||||
#
|
||||
# @param {String} configFile configuration file path
|
||||
# @return {Object} Parsed configuration file
|
||||
#
|
||||
# @throw {InvalidConfigFile} Will throw an error if file doesn't exist
|
||||
# @throw {InvalidConfigFile} Will throw an error if file is not JSON
|
||||
#
|
||||
# @example Read config file
|
||||
# contents = resin.config.loadUserConfig('/Users/me/resin-custom.json')
|
||||
# console.log(contents.remoteUrl)
|
||||
#
|
||||
exports.loadUserConfig = (configFile) ->
|
||||
return if not fs.existsSync(configFile)
|
||||
|
||||
if not fs.statSync(configFile).isFile()
|
||||
throw new errors.InvalidConfigFile(configFile)
|
||||
|
||||
result = fs.readFileSync(configFile, encoding: 'utf8')
|
||||
|
||||
try
|
||||
return JSON.parse(result)
|
||||
catch error
|
||||
throw new errors.InvalidConfigFile(configFile)
|
@ -1,50 +0,0 @@
|
||||
_ = 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)
|
Loading…
x
Reference in New Issue
Block a user