resolve relative paths, add two test cases

This commit is contained in:
SillyFreak 2020-04-13 17:21:28 +02:00 committed by David Humphrey
parent 4aae53839a
commit f1fc53d88f
2 changed files with 29 additions and 1 deletions

View File

@ -387,7 +387,8 @@ Shell.prototype.mkdirp = function(path, callback) {
callback(new Errors.EINVAL('Missing path argument')); callback(new Errors.EINVAL('Missing path argument'));
return; return;
} }
else if (path === '/') { path = Path.resolve(sh.pwd(), path);
if (path === '/') {
callback(); callback();
return; return;
} }

View File

@ -30,6 +30,18 @@ describe('FileSystemShell.mkdirp', function() {
}); });
}); });
it('should succeed if provided path is root, given as a relative path (\'.\' in \'/\')', function(done) {
var fs = util.fs();
var shell = new fs.Shell();
shell.cd('/', function(err) {
expect(err).to.not.exist;
shell.mkdirp('.', function(err) {
expect(err).to.not.exist;
done();
});
});
});
it('should succeed if the directory exists', function(done) { it('should succeed if the directory exists', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = new fs.Shell(); var shell = new fs.Shell();
@ -67,6 +79,21 @@ describe('FileSystemShell.mkdirp', function() {
}); });
}); });
it('should succeed on a folder given as a relative path (\'test\' in \'/\')', function(done) {
var fs = util.fs();
var shell = new fs.Shell();
shell.cd('/', function(err) {
expect(err).to.not.exist;
shell.mkdirp('test', function(err) {
expect(err).to.not.exist;
fs.exists('/test', function(dir){
expect(dir).to.be.true;
done();
});
});
});
});
it('should succeed on a folder with a nonexistant parent (\'/test/test\')', function(done) { it('should succeed on a folder with a nonexistant parent (\'/test/test\')', function(done) {
var fs = util.fs(); var fs = util.fs();
var shell = new fs.Shell(); var shell = new fs.Shell();