Issue 87 - Added fs.fsync() as a no-op, and added tests. Modified documentation.

Made requested changes to tests, functionality; reverted doc changes
This commit is contained in:
kwkofler 2014-04-18 14:27:21 -04:00 committed by David Humphrey
parent a107fe21d7
commit 6a5d9073f3
4 changed files with 60 additions and 0 deletions

View File

@ -1761,6 +1761,16 @@ function read(fs, context, fd, buffer, offset, length, position, callback) {
} }
} }
function fsync(fs, context, fd, callback) {
if(validateInteger(fd, callback) !== fd) return;
var ofd = fs.openFiles[fd];
if(!ofd) {
callback(new Errors.EBADF());
} else {
callback();
}
}
function readFile(fs, context, path, options, callback) { function readFile(fs, context, path, options, callback) {
callback = arguments[arguments.length - 1]; callback = arguments[arguments.length - 1];
options = validate_file_options(options, null, 'r'); options = validate_file_options(options, null, 'r');
@ -2413,6 +2423,7 @@ module.exports = {
stat: stat, stat: stat,
fstat: fstat, fstat: fstat,
link: link, link: link,
fsync: fsync,
read: read, read: read,
readFile: readFile, readFile: readFile,
write: write, write: write,

View File

@ -282,6 +282,7 @@ function FileSystem(options, callback) {
{ name: 'rmdir', promises: true }, { name: 'rmdir', promises: true },
{ name: 'stat', promises: true }, { name: 'stat', promises: true },
{ name: 'fstat' }, { name: 'fstat' },
{ name: 'fsync' },
{ name: 'link', promises: true }, { name: 'link', promises: true },
{ name: 'unlink', promises: true }, { name: 'unlink', promises: true },
{ name: 'read' }, { name: 'read' },

View File

@ -24,6 +24,7 @@ require('./spec/fs.writeFile-readFile.spec');
require('./spec/fs.appendFile.spec'); require('./spec/fs.appendFile.spec');
require('./spec/fs.read.spec'); require('./spec/fs.read.spec');
require('./spec/fs.close.spec'); require('./spec/fs.close.spec');
require('./spec/fs.fsync.spec');
require('./spec/fs.link.spec'); require('./spec/fs.link.spec');
require('./spec/fs.unlink.spec'); require('./spec/fs.unlink.spec');
require('./spec/fs.rename.spec'); require('./spec/fs.rename.spec');

View File

@ -0,0 +1,47 @@
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) {
expect(error).to.not.exist;
fs.close(done);
});
});
});
});
});