Skip to content

Commit

Permalink
test: refactor fs.write() test
Browse files Browse the repository at this point in the history
PR-URL: #16827
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
Patrick Heneise authored and evanlucas committed Nov 13, 2017
1 parent 35fc317 commit 809dc09
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions test/parallel/test-fs-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,43 @@ common.refreshTmpDir();

fs.open(fn, 'w', 0o644, common.mustCall(function(err, fd) {
assert.ifError(err);
console.log('open done');
fs.write(fd, '', 0, 'utf8', function(err, written) {
assert.strictEqual(0, written);
});
fs.write(fd, expected, 0, 'utf8', common.mustCall(function(err, written) {
console.log('write done');

const done = common.mustCall(function(err, written) {
assert.ifError(err);
assert.strictEqual(Buffer.byteLength(expected), written);
fs.closeSync(fd);
const found = fs.readFileSync(fn, 'utf8');
console.log('expected: "%s"', expected);
console.log('found: "%s"', found);
fs.unlinkSync(fn);
assert.strictEqual(expected, found);
}));
});

const written = common.mustCall(function(err, written) {
assert.ifError(err);
assert.strictEqual(0, written);
});

fs.write(fd, '', 0, 'utf8', written);
fs.write(fd, expected, 0, 'utf8', done);
}));

const args = constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC;
fs.open(fn2, args, 0o644, common.mustCall((err, fd) => {
assert.ifError(err);

fs.open(fn2, constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC, 0o644,
common.mustCall((err, fd) => {
assert.ifError(err);
console.log('open done');
fs.write(fd, '', 0, 'utf8', (err, written) => {
assert.strictEqual(0, written);
});
fs.write(fd, expected, 0, 'utf8', common.mustCall((err, written) => {
console.log('write done');
assert.ifError(err);
assert.strictEqual(Buffer.byteLength(expected), written);
fs.closeSync(fd);
const found = fs.readFileSync(fn2, 'utf8');
console.log('expected: "%s"', expected);
console.log('found: "%s"', found);
fs.unlinkSync(fn2);
assert.strictEqual(expected, found);
}));
}));
const done = common.mustCall((err, written) => {
assert.ifError(err);
assert.strictEqual(Buffer.byteLength(expected), written);
fs.closeSync(fd);
const found = fs.readFileSync(fn2, 'utf8');
fs.unlinkSync(fn2);
assert.strictEqual(expected, found);
});

const written = common.mustCall(function(err, written) {
assert.ifError(err);
assert.strictEqual(0, written);
});

fs.write(fd, '', 0, 'utf8', written);
fs.write(fd, expected, 0, 'utf8', done);
}));

0 comments on commit 809dc09

Please sign in to comment.