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

33 lines
803 B
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.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 = Buffer.alloc(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) {
if(error) throw error;
2014-05-23 20:53:50 +00:00
fs.read(fd, buffer, 0, buffer.length, undefined, function(error, result) {
expect(error).to.exist;
expect(result).not.to.exist;
2014-05-23 20:53:50 +00:00
done();
2013-11-27 17:18:09 +00:00
});
});
});
});
});