Skip to content

Commit

Permalink
adds missing fd tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thisconnect committed May 31, 2017
1 parent 5073756 commit 1e0daaa
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/read.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,15 @@ test('read from fd', t => {
flags: 'r'
})
.then(fd => {
return file.read(fd).then(result => {
t.equal(result.toString(), 'Hi!!!\n');
return file.close(fd);
});
return file
.read(fd, {
length: 3
})
.then(result => {
t.equal(result.toString(), 'Hi!');
return file.close(fd);
})
.then(t.end);
})
.catch(error => {
t.error(error);
Expand Down
20 changes: 20 additions & 0 deletions test/readfile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ test('readFile utf8', t => {
});
});

test('readFile from fd', t => {
file
.open(filepath1, {
flags: 'r'
})
.then(fd => {
return file
.readFile(fd)
.then(result => {
t.equal(result.toString(), '0123456789\n');
return file.close(fd);
})
.then(t.end);
})
.catch(error => {
t.error(error);
t.end();
});
});

test('readFile non-existing file', t => {
const path = resolve(__dirname, './data/nothing-here.txt');

Expand Down
24 changes: 24 additions & 0 deletions test/truncate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ test('truncate', t => {
});
});

test('truncate with fd', t => {
file
.open(filepath1, {
flags: 'r+'
})
.then(fd => {
return file
.truncate(fd, {
length: 8
})
.then(() => {
const text = readFileSync(filepath1, 'utf8');
t.equal(text.length, 8, 'text.length is 8');
t.equal(text, 'abcdefgh');
return file.close(fd);
})
.then(t.end);
})
.catch(error => {
t.error(error);
t.end();
});
});

test('truncate all', t => {
file
.truncate(filepath1)
Expand Down
20 changes: 20 additions & 0 deletions test/writefile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ test('writeFile to a new directory', t => {
});
});

test('readFile to fd', t => {
file
.open(file4, {
flags: 'r+'
})
.then(fd => {
return file
.writeFile(fd, '_ an old')
.then(() => {
t.equal(readFileSync(file4, 'utf8'), '_ an old directory');
return file.close(fd);
})
.then(t.end);
})
.catch(error => {
t.error(error);
t.end();
});
});

test('writeFile error', t => {
file
.writeFile()
Expand Down

0 comments on commit 1e0daaa

Please sign in to comment.