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