mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 21:57:51 +00:00
Implement data.has()
This commit is contained in:
parent
d83e269f20
commit
e288d3e85f
@ -27,6 +27,10 @@ exports.set = haltIfNoPrefix (key, value, options, callback) ->
|
||||
keyPath = constructPath(key)
|
||||
fs.writeFile(keyPath, value, options, callback)
|
||||
|
||||
exports.has = haltIfNoPrefix (key, callback) ->
|
||||
keyPath = constructPath(key)
|
||||
fs.exists(keyPath, callback)
|
||||
|
||||
exports.remove = haltIfNoPrefix (key, callback) ->
|
||||
keyPath = constructPath(key)
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
expect = require('chai').expect
|
||||
_ = require('lodash')
|
||||
fsUtils = require('../fs-utils/fs-utils')
|
||||
fs = require('fs')
|
||||
async = require('async')
|
||||
mockFs = require('mock-fs')
|
||||
data = require('./data')
|
||||
@ -52,6 +51,12 @@ describe 'Data:', ->
|
||||
removeDataKey = _.partial(data.remove, 'foobar')
|
||||
expect(removeDataKey).to.throw(Error)
|
||||
|
||||
describe '#has()', ->
|
||||
|
||||
it 'should throw an error', ->
|
||||
hasDataKey = _.partial(data.has, 'foobar')
|
||||
expect(hasDataKey).to.throw(Error)
|
||||
|
||||
describe 'given a prefix', ->
|
||||
|
||||
beforeEach ->
|
||||
@ -92,6 +97,23 @@ describe 'Data:', ->
|
||||
expect(value).to.not.exist
|
||||
done()
|
||||
|
||||
describe '#has()', ->
|
||||
|
||||
it 'should return true if a file exists', (done) ->
|
||||
data.has FILESYSTEM.text.key, (hasKey) ->
|
||||
expect(hasKey).to.be.true
|
||||
done()
|
||||
|
||||
it 'should return true if a directory exists', (done) ->
|
||||
data.has FILESYSTEM.directory.key, (hasKey) ->
|
||||
expect(hasKey).to.be.true
|
||||
done()
|
||||
|
||||
it 'should return false if the file doesn\'t exists', (done) ->
|
||||
data.has 'foobar', (hasKey) ->
|
||||
expect(hasKey).to.be.false
|
||||
done()
|
||||
|
||||
describe '#set()', ->
|
||||
|
||||
writeAndCheckFixture = (fixture) ->
|
||||
@ -166,10 +188,8 @@ describe 'Data:', ->
|
||||
data.remove(directory.key, callback)
|
||||
|
||||
(callback) ->
|
||||
|
||||
# TODO: Implement data.has() to abstract this
|
||||
fs.exists directory.name, (exists) ->
|
||||
expect(exists).to.be.false
|
||||
data.has directory.key, (hasKey) ->
|
||||
expect(hasKey).to.be.false
|
||||
return callback()
|
||||
|
||||
], (error) ->
|
||||
|
Loading…
Reference in New Issue
Block a user