2014-11-07 15:21:48 +00:00
|
|
|
expect = require('chai').expect
|
2014-11-26 18:22:01 +00:00
|
|
|
mock = require('../../../../tests/utils/mock')
|
2014-11-07 15:21:48 +00:00
|
|
|
fsUtils = require('./fs-utils')
|
2014-12-03 16:03:54 +00:00
|
|
|
settings = require('../../settings')
|
2014-11-26 18:22:01 +00:00
|
|
|
data = require('../../data/data')
|
2014-11-07 15:21:48 +00:00
|
|
|
|
2014-11-14 16:58:05 +00:00
|
|
|
FILESYSTEM =
|
|
|
|
text:
|
|
|
|
name: '/tmp/text'
|
|
|
|
contents: 'Hello World'
|
|
|
|
directory:
|
|
|
|
name: '/tmp/directory'
|
2014-11-14 19:48:37 +00:00
|
|
|
contents: {}
|
2014-11-14 16:58:05 +00:00
|
|
|
|
2014-11-07 16:43:10 +00:00
|
|
|
describe 'FsUtils:', ->
|
2014-11-07 15:21:48 +00:00
|
|
|
|
|
|
|
describe '#isValidPath()', ->
|
|
|
|
|
|
|
|
it 'should return false for invalid paths', ->
|
|
|
|
|
|
|
|
for invalidPath in [
|
|
|
|
{ hello: 'world' }
|
|
|
|
1234
|
|
|
|
[ 1, 2, 3 ]
|
|
|
|
undefined
|
|
|
|
null
|
|
|
|
]
|
|
|
|
expect(fsUtils.isValidPath(invalidPath)).to.be.false
|
|
|
|
|
|
|
|
it 'should return true for valid paths', ->
|
|
|
|
|
|
|
|
for validPath in [
|
2014-12-03 16:03:54 +00:00
|
|
|
settings.dataPrefix
|
2014-11-07 15:21:48 +00:00
|
|
|
'/Users/johndoe'
|
|
|
|
'../parent'
|
|
|
|
'./file/../file2'
|
|
|
|
]
|
|
|
|
expect(fsUtils.isValidPath(validPath)).to.be.true
|
2014-11-14 16:58:05 +00:00
|
|
|
|
|
|
|
describe '#isDirectory()', ->
|
|
|
|
|
2014-11-17 19:20:19 +00:00
|
|
|
beforeEach (done) ->
|
2014-11-14 19:48:37 +00:00
|
|
|
mock.fs.init(FILESYSTEM)
|
2014-12-03 16:03:54 +00:00
|
|
|
data.prefix.set(settings.dataPrefix, done)
|
2014-11-14 16:58:05 +00:00
|
|
|
|
|
|
|
afterEach ->
|
2014-11-14 19:48:37 +00:00
|
|
|
mock.fs.restore()
|
2014-11-14 16:58:05 +00:00
|
|
|
|
|
|
|
it 'should return true if directory', (done) ->
|
|
|
|
fsUtils.isDirectory FILESYSTEM.directory.name, (error, isDirectory) ->
|
|
|
|
expect(error).to.not.exist
|
|
|
|
expect(isDirectory).to.be.true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should return false if not a directory', (done) ->
|
|
|
|
fsUtils.isDirectory FILESYSTEM.text.name, (error, isDirectory) ->
|
|
|
|
expect(error).to.not.exist
|
|
|
|
expect(isDirectory).to.be.false
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should return an error if the path doesn\'t exists', (done) ->
|
|
|
|
fsUtils.isDirectory '/nonexistantpath', (error, isDirectory) ->
|
|
|
|
expect(error).to.exist
|
|
|
|
expect(isDirectory).to.be.undefined
|
|
|
|
done()
|