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

102 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

2014-05-23 20:53:50 +00:00
var Filer = require('../..');
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");
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");
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");
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");
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");
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
});
});
});
});
});