diff options
author | willhayslett <william.hayslettjr@gmail.com> | 2018-03-25 21:56:06 -0500 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-04-04 19:05:29 -0700 |
commit | 126b03e2f9e5a695b025a1a70eb49b88de43d080 (patch) | |
tree | 6ec5dd3826a38da12d0151765f5f7d10b85d7bf6 /test/parallel/test-fs-promises-file-handle-append-file.js | |
parent | 0876a0314d15129e8b29cb6e9753b886086cbfe2 (diff) | |
download | android-node-v8-126b03e2f9e5a695b025a1a70eb49b88de43d080.tar.gz android-node-v8-126b03e2f9e5a695b025a1a70eb49b88de43d080.tar.bz2 android-node-v8-126b03e2f9e5a695b025a1a70eb49b88de43d080.zip |
test: add tests for fs/promises.js fileHandle methods
Working to increase test code coverage for fs/promises.js.
Added tests for fileHandle.appendFile and fileHandle.chmod.
PR-URL: https://github.com/nodejs/node/pull/19605
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/parallel/test-fs-promises-file-handle-append-file.js')
-rw-r--r-- | test/parallel/test-fs-promises-file-handle-append-file.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/parallel/test-fs-promises-file-handle-append-file.js b/test/parallel/test-fs-promises-file-handle-append-file.js new file mode 100644 index 0000000000..38336a2b43 --- /dev/null +++ b/test/parallel/test-fs-promises-file-handle-append-file.js @@ -0,0 +1,41 @@ +'use strict'; + +const common = require('../common'); + +// The following tests validate base functionality for the fs/promises +// FileHandle.appendFile method. + +const fs = require('fs'); +const { open } = require('fs/promises'); +const path = require('path'); +const tmpdir = require('../common/tmpdir'); +const assert = require('assert'); +const tmpDir = tmpdir.path; + +tmpdir.refresh(); +common.crashOnUnhandledRejection(); + +async function validateAppendBuffer() { + const filePath = path.resolve(tmpDir, 'tmp-append-file-buffer.txt'); + const fileHandle = await open(filePath, 'a'); + const buffer = Buffer.from('a&Dp'.repeat(100), 'utf8'); + + await fileHandle.appendFile(buffer); + const appendedFileData = fs.readFileSync(filePath); + assert.deepStrictEqual(appendedFileData, buffer); +} + +async function validateAppendString() { + const filePath = path.resolve(tmpDir, 'tmp-append-file-string.txt'); + const fileHandle = await open(filePath, 'a'); + const string = 'x~yz'.repeat(100); + + await fileHandle.appendFile(string); + const stringAsBuffer = Buffer.from(string, 'utf8'); + const appendedFileData = fs.readFileSync(filePath); + assert.deepStrictEqual(appendedFileData, stringAsBuffer); +} + +validateAppendBuffer() + .then(validateAppendString) + .then(common.mustCall()); |