2014-01-21 21:25:09 +00:00
|
|
|
define(["Filer", "util"], function(Filer, util) {
|
2013-11-27 17:18:09 +00:00
|
|
|
|
|
|
|
describe('fs.rmdir', function() {
|
2014-01-21 21:25:09 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2013-11-27 17:18:09 +00:00
|
|
|
|
|
|
|
it('should be a function', function() {
|
2014-01-21 21:25:09 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
expect(fs.rmdir).to.be.a('function');
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +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-01-21 21:25:09 +00:00
|
|
|
fs.rmdir('/tmp/mydir', function(error) {
|
|
|
|
expect(error).to.exist;
|
2014-04-17 15:53:55 +00:00
|
|
|
expect(error.code).to.equal("ENOENT");
|
2014-01-21 21:25:09 +00:00
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +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-01-21 21:25:09 +00:00
|
|
|
fs.rmdir('/', function(error) {
|
|
|
|
expect(error).to.exist;
|
2014-04-17 15:53:55 +00:00
|
|
|
expect(error.code).to.equal("EBUSY");
|
2014-01-21 21:25:09 +00:00
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +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-01-21 21:25:09 +00:00
|
|
|
fs.mkdir('/tmp', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.mkdir('/tmp/mydir', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.rmdir('/', function(error) {
|
|
|
|
expect(error).to.exist;
|
2014-04-17 15:53:55 +00:00
|
|
|
expect(error.code).to.equal("EBUSY");
|
2014-01-21 21:25:09 +00:00
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should return an error if the path is not a directory', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.mkdir('/tmp', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.open('/tmp/myfile', 'w', function(error, fd) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.close(fd, function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.rmdir('/tmp/myfile', function(error) {
|
|
|
|
expect(error).to.exist;
|
2014-04-17 15:53:55 +00:00
|
|
|
expect(error.code).to.equal("ENOTDIR");
|
2014-01-21 21:25:09 +00:00
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +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-01-21 21:25:09 +00:00
|
|
|
fs.mkdir('/tmp', function (error) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.symlink('/tmp', '/tmp/myfile', function (error) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.rmdir('/tmp/myfile', function (error) {
|
|
|
|
expect(error).to.exist;
|
2014-04-17 15:53:55 +00:00
|
|
|
expect(error.code).to.equal("ENOTDIR");
|
2014-01-21 21:25:09 +00:00
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-01-21 21:25:09 +00:00
|
|
|
it('should remove an existing directory', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
|
|
|
|
fs.mkdir('/tmp', function(error) {
|
|
|
|
if(error) throw error;
|
|
|
|
fs.rmdir('/tmp', function(error) {
|
|
|
|
expect(error).not.to.exist;
|
|
|
|
if(error) throw error;
|
|
|
|
fs.stat('/tmp', function(error, stats) {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(stats).not.to.exist;
|
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|