filer/tests/spec/fs.rename.spec.js

51 lines
1.2 KiB
JavaScript
Raw 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.rename', 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.rename).to.be.a('function');
});
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
it('should rename an existing file', function(done) {
var complete1 = false;
var complete2 = false;
var fs = util.fs();
2014-05-23 20:53:50 +00:00
function maybeDone() {
if(complete1 && complete2) {
done();
}
2014-05-23 20:53:50 +00:00
}
fs.open('/myfile', 'w+', function(error, fd) {
if(error) throw error;
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
fs.close(fd, function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.rename('/myfile', '/myotherfile', function(error) {
2013-11-27 17:18:09 +00:00
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.stat('/myfile', function(error, result) {
expect(error).to.exist;
complete1 = true;
maybeDone();
});
fs.stat('/myotherfile', function(error, result) {
expect(error).not.to.exist;
expect(result.nlinks).to.equal(1);
complete2 = true;
maybeDone();
2013-11-27 17:18:09 +00:00
});
});
});
});
});
});