Fixed Issue #483 for a test done for fs.mknod promise (#509)

* test done for fs.mknod promise

* fixing whitespaces
This commit is contained in:
Nick Skuybeda 2018-10-09 12:43:45 -04:00 committed by David Humphrey
parent a8759b1e38
commit 86b6b2a907
1 changed files with 32 additions and 21 deletions

View File

@ -1,64 +1,64 @@
var util = require('../lib/test-utils.js'); var util = require('../lib/test-utils.js');
var expect = require('chai').expect; var expect = require('chai').expect;
describe('fs.mknod', function() { describe('fs.mknod', function(){
beforeEach(util.setup); beforeEach(util.setup);
afterEach(util.cleanup); afterEach(util.cleanup);
it('should be a function', function(done) { it('should be a function', function(done){
var fs = util.fs(); var fs = util.fs();
expect(fs.mknod).to.be.a('function'); expect(fs.mknod).to.be.a('function');
done(); done();
}); });
it('should return an error if part of the parent path does not exist', function(done) { it('should return an error if part of the parent path does not exist', function(done){
var fs = util.fs(); var fs = util.fs();
fs.mknod('/dir/mydir', 'DIRECTORY', function(error) { fs.mknod('/dir/mydir', 'DIRECTORY', function(error){
expect(error.code).to.equal('ENOENT'); expect(error.code).to.equal('ENOENT');
done(); done();
}); });
}); });
it('should return an error if path already exists', function(done) { it('should return an error if path already exists', function(done){
var fs = util.fs(); var fs = util.fs();
fs.mknod('/', 'DIRECTORY', function(error) { fs.mknod('/', 'DIRECTORY', function(error){
expect(error.code).to.equal('EEXIST'); expect(error.code).to.equal('EEXIST');
done(); done();
}); });
}); });
it('should return an error if the parent node is not a directory', function(done) { it('should return an error if the parent node is not a directory', function(done){
var fs = util.fs(); var fs = util.fs();
fs.mknod('/file', 'FILE' , function(error) { fs.mknod('/file', 'FILE', function(error){
if(error) throw error; if (error) throw error;
fs.mknod('/file/myfile', 'FILE', function(error) { fs.mknod('/file/myfile', 'FILE', function(error){
expect(error.code).to.equal('ENOTDIR'); expect(error.code).to.equal('ENOTDIR');
done(); done();
}); });
}); });
}); });
it('should return an error if the mode provided is not DIRECTORY or FILE', function(done) { it('should return an error if the mode provided is not DIRECTORY or FILE', function(done){
var fs = util.fs(); var fs = util.fs();
fs.mknod('/symlink', 'SYMLINK', function(error) { fs.mknod('/symlink', 'SYMLINK', function(error){
expect(error).to.exist; expect(error).to.exist;
expect(error.code).to.equal('EINVAL'); expect(error.code).to.equal('EINVAL');
done(); done();
}); });
}); });
it('should make a new directory', function(done) { it('should make a new directory', function(done){
var fs = util.fs(); var fs = util.fs();
fs.mknod('/dir', 'DIRECTORY', function(error) { fs.mknod('/dir', 'DIRECTORY', function(error){
if(error) throw error; if (error) throw error;
fs.stat('/dir', function(error, stats) { fs.stat('/dir', function(error, stats){
expect(error).not.to.exist; expect(error).not.to.exist;
expect(stats.type).to.equal('DIRECTORY'); expect(stats.type).to.equal('DIRECTORY');
done(); done();
@ -66,17 +66,28 @@ describe('fs.mknod', function() {
}); });
}); });
it('should make a new file', function(done) { it('should make a new file', function(done){
var fs = util.fs(); var fs = util.fs();
fs.mknod('/file', 'FILE' , function(error) { fs.mknod('/file', 'FILE', function(error){
if(error) throw error; if (error) throw error;
fs.stat('/file', function(error, result) { fs.stat('/file', function(error, result){
expect(error).not.to.exist; expect(error).not.to.exist;
expect(result.type).to.equal('FILE'); expect(result.type).to.equal('FILE');
done(); done();
}); });
}); });
}); });
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');
});
});
});
}); });