filer/tests/spec/fs.rmdir.spec.js

124 lines
3.3 KiB
JavaScript
Raw Normal View History

2014-05-23 20:53:50 +00:00
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
describe('fs.rmdir', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
it('should be a function', function() {
var fs = util.fs();
expect(fs.rmdir).to.be.a('function');
});
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
it('should return an error if the path does not exist', function(done) {
var fs = util.fs();
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
fs.rmdir('/tmp/mydir', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOENT');
2014-05-23 20:53:50 +00:00
done();
2013-11-27 17:18:09 +00:00
});
2014-05-23 20:53:50 +00:00
});
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
it('should return an error if attempting to remove the root directory', function(done) {
var fs = util.fs();
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
fs.rmdir('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('EBUSY');
2014-05-23 20:53:50 +00:00
done();
2013-11-27 17:18:09 +00:00
});
2014-05-23 20:53:50 +00:00
});
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
it('should return an error if the directory is not empty', function(done) {
var fs = util.fs();
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
fs.mkdir('/tmp', function(error) {
if(error) throw error;
fs.mkdir('/tmp/mydir', function(error) {
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.rmdir('/', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('EBUSY');
2014-05-23 20:53:50 +00:00
done();
2013-11-27 17:18:09 +00:00
});
});
});
2014-05-23 20:53:50 +00:00
});
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
it('should return an error if the path is not a directory', function(done) {
var fs = util.fs();
2014-05-23 20:53:50 +00:00
fs.mkdir('/tmp', function(error) {
if(error) throw error;
fs.open('/tmp/myfile', 'w', function(error, fd) {
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.close(fd, function(error) {
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.rmdir('/tmp/myfile', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOTDIR');
2014-05-23 20:53:50 +00:00
done();
2013-11-27 17:18:09 +00:00
});
});
});
});
2014-05-23 20:53:50 +00:00
});
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
it('should return an error if the path is a symbolic link', function(done) {
var fs = util.fs();
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
fs.mkdir('/tmp', function (error) {
if(error) throw error;
fs.symlink('/tmp', '/tmp/myfile', function (error) {
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.rmdir('/tmp/myfile', function (error) {
expect(error).to.exist;
expect(error.code).to.equal('ENOTDIR');
2014-05-23 20:53:50 +00:00
done();
2013-11-27 17:18:09 +00:00
});
});
});
2014-05-23 20:53:50 +00:00
});
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
it('should remove an existing directory', function(done) {
var fs = util.fs();
2014-05-23 20:53:50 +00:00
fs.mkdir('/tmp', function(error) {
if(error) throw error;
fs.rmdir('/tmp', function(error) {
expect(error).not.to.exist;
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.stat('/tmp', function(error, stats) {
expect(error).to.exist;
expect(stats).not.to.exist;
done();
2013-11-27 17:18:09 +00:00
});
});
});
});
it('(promise) should be a function', function() {
var fsPromises = util.fs().promises;
expect(fsPromises.rmdir).to.be.a('function');
});
it('(promise) should return an error if the path does not exist', function() {
var fsPromises = util.fs().promises;
return fsPromises.rmdir('/tmp/mydir')
.catch(error => {
expect(error).to.exist;
expect(error.code).to.equal('ENOENT');
});
});
it('(promise) should return an error if attempting to remove the root directory', function() {
var fsPromises = util.fs().promises;
return fsPromises.rmdir('/')
.catch(error => {
expect(error).to.exist;
expect(error.code).to.equal('EBUSY');
});
});
2013-11-27 17:18:09 +00:00
});