filer/tests/spec/fs.fsync.spec.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

var util = require('../lib/test-utils.js');
var expect = require('chai').expect;
describe('fs.fsync', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should be a function', function() {
var fs = util.fs();
expect(fs.fsync).to.be.a('function');
});
it('should return error when fd is not a number', function(done) {
var fs = util.fs();
fs.fsync('1', function(error) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
done();
});
});
it('should return error when fd is invalid', function(done) {
var fs = util.fs();
fs.fsync(1, function(error) {
expect(error).to.exist;
expect(error.code).to.equal('EBADF');
done();
});
});
it('should not error if the fd is valid', function(done) {
var fs = util.fs();
fs.writeFile('/myfile', 'contents', function(error) {
if(error) throw error;
fs.open('/myfile', 'r', function(error, fd) {
if(error) throw error;
fs.fsync(fd, function(error) {
2018-12-02 04:59:36 +00:00
expect(error).not.to.exist;
fs.close(fd, done);
});
});
});
});
});