Fix Issue #389 - add test for truncate with undefined length

This commit is contained in:
David Humphrey (:humph) david.humphrey@senecacollege.ca 2018-09-17 15:04:58 -04:00
parent ed60c0b1fb
commit ebe44a3cae
1 changed files with 29 additions and 0 deletions

View File

@ -125,6 +125,35 @@ describe('fs.truncate', function() {
}); });
}); });
it('should default to 0 when length is 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;
fs.close(fd, function(error) {
if(error) throw error;
fs.truncate('/myfile', undefined, function(error) {
expect(error).to.not.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) { it('should truncate a valid descriptor', function(done) {
var fs = util.fs(); var fs = util.fs();
var buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]); var buffer = new Buffer([1, 2, 3, 4, 5, 6, 7, 8]);