diff options
author | Rongjian Zhang <pd4d10@gmail.com> | 2021-05-08 21:35:53 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-05-22 01:44:40 +0300 |
commit | a1f590ebd609c72587fc9adda43c1b530e15bf11 (patch) | |
tree | 223f7fb5cdfafd1947f81d0f2a19c75935ee6693 /test | |
parent | 5a1140222379f7b75203648e73b5daf7d3d3ef76 (diff) |
test: improve coverage of lib/fs.js
PR-URL: https://github.com/nodejs/node/pull/38604
Refs: https://coverage.nodejs.org/coverage-29f1b609ba5d12d3/lib/fs.js.html#L2045
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-fs-write-file.js | 10 | ||||
-rw-r--r-- | test/parallel/test-fs-writefile-with-fd.js | 28 |
2 files changed, 38 insertions, 0 deletions
diff --git a/test/parallel/test-fs-write-file.js b/test/parallel/test-fs-write-file.js index 3d0fd48f05f..45cbde4a90e 100644 --- a/test/parallel/test-fs-write-file.js +++ b/test/parallel/test-fs-write-file.js @@ -95,3 +95,13 @@ fs.open(filename4, 'w+', common.mustSucceed((fd) => { process.nextTick(() => controller.abort()); } + +{ + // Test read-only mode + const filename = join(tmpdir.path, 'test6.txt'); + fs.writeFileSync(filename, ''); + + // TODO: Correct the error type + const expectedError = common.isWindows ? /EPERM/ : /EBADF/; + fs.writeFile(filename, s, { flag: 'r' }, common.expectsError(expectedError)); +} diff --git a/test/parallel/test-fs-writefile-with-fd.js b/test/parallel/test-fs-writefile-with-fd.js index 1effc519627..2af5b39adbc 100644 --- a/test/parallel/test-fs-writefile-with-fd.js +++ b/test/parallel/test-fs-writefile-with-fd.js @@ -55,3 +55,31 @@ tmpdir.refresh(); })); })); } + + +// Test read-only file descriptor +{ + // TODO(pd4d10): https://github.com/nodejs/node/issues/38607 + const expectedError = common.isWindows ? /EPERM/ : /EBADF/; + + const file = join(tmpdir.path, 'test.txt'); + + fs.open(file, 'r', common.mustSucceed((fd) => { + fs.writeFile(fd, 'World', common.expectsError(expectedError)); + })); +} + +// Test with an AbortSignal +{ + const controller = new AbortController(); + const signal = controller.signal; + const file = join(tmpdir.path, 'test.txt'); + + fs.open(file, 'w', common.mustSucceed((fd) => { + fs.writeFile(fd, 'World', { signal }, common.expectsError({ + name: 'AbortError' + })); + })); + + controller.abort(); +} |