Skip to content

Commit

Permalink
test: cover 'close' method in Dir class
Browse files Browse the repository at this point in the history
cover 'close' method (in Dir class) with tests
Add 2 tests for full covering of method 'close' in class Dir
1. If pass smth that not string as a callback - throw an exception
2. If do .close() on already closed directory - throw an exception

PR-URL: #30310
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
artmaks authored and targos committed Jan 13, 2020
1 parent f8d3ea9 commit c5f22cb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/parallel/test-fs-opendir.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const dirclosedError = {
code: 'ERR_DIR_CLOSED'
};

const invalidCallbackObj = {
code: 'ERR_INVALID_CALLBACK',
name: 'TypeError'
};

// Check the opendir Sync version
{
const dir = fs.opendirSync(testDir);
Expand Down Expand Up @@ -209,3 +214,19 @@ for (const bufferSize of ['', '1', null]) {
assertDirent(dir.readSync());
dir.close();
}

// Check that when passing a string instead of function - throw an exception
async function doAsyncIterInvalidCallbackTest() {
const dir = await fs.promises.opendir(testDir);
assert.throws(() => dir.close('not function'), invalidCallbackObj);
}
doAsyncIterInvalidCallbackTest().then(common.mustCall());

// Check if directory already closed - throw an exception
async function doAsyncIterDirClosedTest() {
const dir = await fs.promises.opendir(testDir);
await dir.close();

assert.throws(() => dir.close(), dirclosedError);
}
doAsyncIterDirClosedTest().then(common.mustCall());

0 comments on commit c5f22cb

Please sign in to comment.