Merge pull request #395 from humphd/issue-393

Fix #393: add test for truncate with length undefined
This commit is contained in:
David Humphrey 2018-10-03 18:13:08 -04:00 committed by GitHub
commit c84dd14f5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 0 deletions

View File

@ -127,6 +127,37 @@ describe('fs.truncate', function() {
});
});
it('should assume a length of 0 if passed undefined', function(done) {
var fs = util.fs();
var buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]);
fs.open('/myfile', 'w', function(error, result) {
if(error) throw error;
var fd = result;
fs.write(fd, buffer, 0, buffer.length, 0, function(error, result) {
if(error) throw error;
expect(result).to.equal(buffer.length);
fs.close(fd, function(error) {
if(error) throw error;
// We want to use undefined to see that it defaults to 0
fs.truncate('/myfile', undefined, function(error) {
expect(error).not.to.exist;
fs.stat('/myfile', function(error, result) {
if(error) throw error;
expect(result.size).to.equal(0);
done();
});
});
});
});
});
});
it('should truncate a valid descriptor', function(done) {
var fs = util.fs();
var buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]);