filer/tests/spec/fs.close.spec.js

31 lines
766 B
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.close', 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(typeof fs.close).to.equal('function');
});
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
it('should release the file descriptor', function(done) {
var buffer = new Filer.Buffer(0);
2014-05-23 20:53:50 +00:00
var fs = util.fs();
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
fs.open('/myfile', 'w+', function(error, result) {
if(error) throw error;
2013-11-27 17:18:09 +00:00
2014-05-23 20:53:50 +00:00
var fd = result;
fs.close(fd, function(error) {
fs.read(fd, buffer, 0, buffer.length, undefined, function(error, result) {
expect(error).to.exist;
done();
2013-11-27 17:18:09 +00:00
});
});
});
});
});