2014-05-23 20:53:50 +00:00
|
|
|
var util = require('../../lib/test-utils.js');
|
|
|
|
var expect = require('chai').expect;
|
2014-03-14 04:03:29 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
describe('FileSystemShell.mkdirp', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2014-03-14 04:03:29 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should be a function', function() {
|
|
|
|
var shell = util.shell();
|
|
|
|
expect(shell.mkdirp).to.be.a('function');
|
|
|
|
});
|
2014-03-14 04:03:29 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should fail without a path provided', function(done) {
|
2018-12-21 01:11:51 +00:00
|
|
|
var shell = util.shell();
|
2014-03-14 04:03:29 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
shell.mkdirp(null, function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.code).to.equal('EINVAL');
|
|
|
|
done();
|
2014-03-14 04:03:29 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-03-14 04:03:29 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should succeed if provided path is root', function(done) {
|
2018-12-21 01:11:51 +00:00
|
|
|
var shell = util.shell();
|
2014-05-23 20:53:50 +00:00
|
|
|
shell.mkdirp('/', function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
done();
|
2014-03-14 04:03:29 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-03-14 04:03:29 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should succeed if the directory exists', function(done) {
|
|
|
|
var fs = util.fs();
|
2018-12-21 01:11:51 +00:00
|
|
|
var shell = util.shell();
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.mkdir('/test', function(err){
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
shell.mkdirp('/test',function(err) {
|
2014-03-14 04:03:29 +00:00
|
|
|
expect(err).to.not.exist;
|
2014-05-23 20:53:50 +00:00
|
|
|
done();
|
|
|
|
});
|
2014-03-14 04:03:29 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-03-14 04:03:29 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('fail if a file name is provided', function(done) {
|
|
|
|
var fs = util.fs();
|
2018-12-21 01:11:51 +00:00
|
|
|
var shell = util.shell();
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.writeFile('/test.txt', 'test', function(err){
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
shell.mkdirp('/test.txt', function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.code).to.equal('ENOTDIR');
|
|
|
|
done();
|
2014-03-14 04:03:29 +00:00
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-03-14 04:03:29 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should succeed on a folder on root (\'/test\')', function(done) {
|
|
|
|
var fs = util.fs();
|
2018-12-21 01:11:51 +00:00
|
|
|
var shell = util.shell();
|
2014-05-23 20:53:50 +00:00
|
|
|
shell.mkdirp('/test', function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
fs.exists('/test', function(dir){
|
|
|
|
expect(dir).to.be.true;
|
|
|
|
done();
|
2014-03-14 04:03:29 +00:00
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-03-14 04:03:29 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should succeed on a folder with a nonexistant parent (\'/test/test\')', function(done) {
|
|
|
|
var fs = util.fs();
|
2018-12-21 01:11:51 +00:00
|
|
|
var shell = util.shell();
|
2014-05-23 20:53:50 +00:00
|
|
|
shell.mkdirp('/test/test', function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
fs.exists('/test', function(dir1){
|
|
|
|
expect(dir1).to.be.true;
|
|
|
|
fs.exists('/test/test', function(dir2){
|
|
|
|
expect(dir2).to.be.true;
|
|
|
|
done();
|
2014-03-14 04:03:29 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-03-14 04:03:29 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should fail on a folder with a file for its parent (\'/test.txt/test\')', function(done) {
|
|
|
|
var fs = util.fs();
|
2018-12-21 01:11:51 +00:00
|
|
|
var shell = util.shell();
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.writeFile('/test.txt', 'test', function(err){
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
shell.mkdirp('/test.txt/test', function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.code).to.equal('ENOTDIR');
|
|
|
|
done();
|
2014-03-14 04:03:29 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|