Unit tests for mkdtemp method added (issue #394)

This commit is contained in:
Alexei Kozachenko 2018-09-28 12:01:23 -04:00
parent 57bcf72209
commit 8ac7c7dfb0
2 changed files with 52 additions and 0 deletions

View File

@ -14,6 +14,7 @@ require('./spec/fs.lstat.spec');
require('./spec/fs.exists.spec'); require('./spec/fs.exists.spec');
require('./spec/fs.mknod.spec'); require('./spec/fs.mknod.spec');
require('./spec/fs.mkdir.spec'); require('./spec/fs.mkdir.spec');
require('./spec/fs.mkdtemp.spec');
require('./spec/fs.readdir.spec'); require('./spec/fs.readdir.spec');
require('./spec/fs.rmdir.spec'); require('./spec/fs.rmdir.spec');
require('./spec/fs.open.spec'); require('./spec/fs.open.spec');

View File

@ -0,0 +1,51 @@
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.mkdtemp', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.mkdtemp).to.be.a('function');
});
it('should craete temp dir with specified prefix', function(done) {
var fs = util.fs();
fs.mkdtemp('foo', function(error, path) {
expect(error).not.to.exist;
expect(path).to.match(/foo.{6}/);
done();
});
});
it('should craete temp dir inside existing directory', function(done) {
var fs = util.fs();
fs.mkdir('/myDir', (error) => {
expect(error).not.to.exist;
fs.mkdtemp('/myDir/foo', function(error, path) {
expect(error).not.to.exist;
expect(path).to.match(/foo.{6}/);
done();
});
});
});
it('should not create temp dir without prefix', function(done) {
var fs = util.fs();
fs.mkdtemp('', function(error, path) {
expect(error).to.exist;
expect(path).to.be.equal('');
done();
});
});
it('should not create temp dir inside non existing dir', function(done) {
var fs = util.fs();
fs.mkdtemp('/doesNotExists/foo', function(error, path) {
expect(error).to.exist;
expect(error.code).to.be.equal('ENOENT');
expect(path).to.exist;
done();
});
});
});