mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-23 07:22:22 +00:00
Make data.prefix.set() async
This commit is contained in:
parent
5eeb4e04ee
commit
11998a63cd
@ -5,11 +5,12 @@ prefix = null
|
||||
exports.get = ->
|
||||
return prefix
|
||||
|
||||
exports.set = (newPrefix) ->
|
||||
exports.set = (newPrefix, callback) ->
|
||||
if not fsUtils.isValidPath(newPrefix)
|
||||
throw new Error('Invalid path')
|
||||
return callback?(new Error('Invalid path'))
|
||||
|
||||
prefix = newPrefix
|
||||
return callback?(null, prefix)
|
||||
|
||||
exports.clear = ->
|
||||
prefix = null
|
||||
|
@ -22,19 +22,22 @@ describe 'DataPrefix:', ->
|
||||
|
||||
describe '#set()', ->
|
||||
|
||||
it 'should be able to set a prefix', ->
|
||||
it 'should be able to set a prefix', (done) ->
|
||||
expect(dataPrefix.get()).to.not.exist
|
||||
dataPrefix.set(PREFIXES.main)
|
||||
dataPrefix.set PREFIXES.main, (error) ->
|
||||
expect(error).to.not.exist
|
||||
expect(dataPrefix.get()).to.equal(PREFIXES.main)
|
||||
done()
|
||||
|
||||
it 'should throw an error if passing an invalid path', ->
|
||||
setInvalidPrefix = _.partial(dataPrefix.set, PREFIXES.invalid)
|
||||
expect(setInvalidPrefix).to.throw(Error)
|
||||
it 'should throw an error if passing an invalid path', (done) ->
|
||||
dataPrefix.set PREFIXES.invalid, (error) ->
|
||||
expect(error).to.be.an.instanceof(Error)
|
||||
done()
|
||||
|
||||
describe 'given a prefix', ->
|
||||
|
||||
beforeEach ->
|
||||
dataPrefix.set(PREFIXES.main)
|
||||
beforeEach (done) ->
|
||||
dataPrefix.set(PREFIXES.main, done)
|
||||
|
||||
describe '#get()', ->
|
||||
|
||||
@ -43,10 +46,12 @@ describe 'DataPrefix:', ->
|
||||
|
||||
describe '#set()', ->
|
||||
|
||||
it 'should be able to override the prefix', ->
|
||||
it 'should be able to override the prefix', (done) ->
|
||||
expect(dataPrefix.get()).to.equal(PREFIXES.main)
|
||||
dataPrefix.set(PREFIXES.new)
|
||||
dataPrefix.set PREFIXES.new, (error) ->
|
||||
expect(error).to.not.exist
|
||||
expect(dataPrefix.get()).to.equal(PREFIXES.new)
|
||||
done()
|
||||
|
||||
describe '#clear()', ->
|
||||
|
||||
|
@ -58,9 +58,9 @@ describe 'Data:', ->
|
||||
|
||||
describe 'given a prefix', ->
|
||||
|
||||
beforeEach ->
|
||||
beforeEach (done) ->
|
||||
mock.fs.init(FILESYSTEM)
|
||||
data.prefix.set(config.dataPrefix)
|
||||
data.prefix.set(config.dataPrefix, done)
|
||||
|
||||
afterEach ->
|
||||
mock.fs.restore()
|
||||
|
@ -39,9 +39,9 @@ describe 'FsUtils:', ->
|
||||
|
||||
describe '#isDirectory()', ->
|
||||
|
||||
beforeEach ->
|
||||
beforeEach (done) ->
|
||||
mock.fs.init(FILESYSTEM)
|
||||
data.prefix.set(config.dataPrefix)
|
||||
data.prefix.set(config.dataPrefix, done)
|
||||
|
||||
afterEach ->
|
||||
mock.fs.restore()
|
||||
|
Loading…
Reference in New Issue
Block a user