2014-05-23 20:53:50 +00:00
|
|
|
var util = require('../lib/test-utils.js');
|
|
|
|
var expect = require('chai').expect;
|
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
describe('fs.mknod', function(){
|
2014-05-23 20:53:50 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
it('should be a function', function(done){
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
expect(fs.mknod).to.be.a('function');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
it('should return an error if part of the parent path does not exist', function(done){
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
fs.mknod('/dir/mydir', 'DIRECTORY', function(error){
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(error.code).to.equal('ENOENT');
|
2014-05-13 22:10:11 +00:00
|
|
|
done();
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-05-13 22:10:11 +00:00
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
it('should return an error if path already exists', function(done){
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
fs.mknod('/', 'DIRECTORY', function(error){
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(error.code).to.equal('EEXIST');
|
|
|
|
done();
|
2014-05-13 22:10:11 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
it('should return an error if the parent node is not a directory', function(done){
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
fs.mknod('/file', 'FILE', function(error){
|
|
|
|
if (error) throw error;
|
2018-07-27 14:39:34 +00:00
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
fs.mknod('/file/myfile', 'FILE', function(error){
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(error.code).to.equal('ENOTDIR');
|
2014-05-13 22:10:11 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-05-13 22:10:11 +00:00
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
it('should return an error if the mode provided is not DIRECTORY or FILE', function(done){
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
fs.mknod('/symlink', 'SYMLINK', function(error){
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(error).to.exist;
|
|
|
|
expect(error.code).to.equal('EINVAL');
|
|
|
|
done();
|
2014-05-13 22:10:11 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
it('should make a new directory', function(done){
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
fs.mknod('/dir', 'DIRECTORY', function(error){
|
|
|
|
if (error) throw error;
|
2014-05-23 20:53:50 +00:00
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
fs.stat('/dir', function(error, stats){
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(error).not.to.exist;
|
2018-11-28 18:54:20 +00:00
|
|
|
expect(stats.isDirectory()).to.be.true;
|
2014-05-13 22:10:11 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
it('should make a new file', function(done){
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
|
2018-10-09 16:43:45 +00:00
|
|
|
fs.mknod('/file', 'FILE', function(error){
|
|
|
|
if (error) throw error;
|
|
|
|
|
|
|
|
fs.stat('/file', function(error, result){
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(error).not.to.exist;
|
2018-11-28 18:54:20 +00:00
|
|
|
expect(result.isFile()).to.be.true;
|
2014-05-23 20:53:50 +00:00
|
|
|
done();
|
2014-05-13 22:10:11 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-09 16:43:45 +00:00
|
|
|
describe('Promise test mknod', function(){
|
|
|
|
|
|
|
|
it('should return an error if part of the parent path does not exist', function(){
|
|
|
|
var fs = util.fs().promises;
|
|
|
|
|
|
|
|
return fs.mknod('/dir/mydir', 'DIRECTORY')
|
|
|
|
.catch(error => {
|
|
|
|
expect(error.code).to.equal('ENOENT');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|