From fe7d902a2c28ebe2b2be5c83ce72c5754d8f909d Mon Sep 17 00:00:00 2001 From: Julia Yatsenko Date: Wed, 19 Dec 2018 18:13:02 -0500 Subject: [PATCH 1/2] fix #635: added test for fs.ftruncate() --- tests/spec/fs.ftruncate.spec.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/spec/fs.ftruncate.spec.js b/tests/spec/fs.ftruncate.spec.js index 9f6726dd..7940561f 100644 --- a/tests/spec/fs.ftruncate.spec.js +++ b/tests/spec/fs.ftruncate.spec.js @@ -10,6 +10,27 @@ describe('fs.ftruncate', function() { expect(fs.ftruncate).to.be.a('function'); }); + it('should return an error if length is not an integer', function(done) { + let fs = util.fs(); + let contents = 'This is a file.'; + + fs.writeFile('/myfile', contents, function(error) { + if(error) throw error; + + fs.open('/myfile', 'w', function(err, fd) { + + fs.ftruncate(fd, 'notAnInteger', function(error) { + expect(error).to.exist; + expect(error.code).to.equal('EINVAL'); + done(); + }); + + // Close file descriptor when done + fs.close(fd); + }); + }); + }); + it('should return an error if length is negative', function(done) { let fs = util.fs(); let contents = 'This is a file.'; From cef05cf805f819a920038a5d6efa081c54e8a091 Mon Sep 17 00:00:00 2001 From: Julia Yatsenko Date: Wed, 19 Dec 2018 18:49:05 -0500 Subject: [PATCH 2/2] fix #637: added tests for fs.fsync() --- tests/spec/fs.fsync.spec.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/spec/fs.fsync.spec.js b/tests/spec/fs.fsync.spec.js index 6c218770..ce68f024 100644 --- a/tests/spec/fs.fsync.spec.js +++ b/tests/spec/fs.fsync.spec.js @@ -12,16 +12,18 @@ describe('fs.fsync', function() { it('should return error when fd is not a number', function(done) { var fs = util.fs(); - fs.fsync('1', function(error) { + fs.fsync('notAnInteger', 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) { + it('should return an error if file descriptor is negative', function(done) { + let fs = util.fs(); + + // File descriptor should be a non-negative number + fs.fsync(-1, function(error) { expect(error).to.exist; expect(error.code).to.equal('EBADF'); done();