GeezerVison is showing github.com — test: add filehandle sync() and datasync() tests · nodejs/node@678313d
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | +const fixtures = require('../common/fixtures'); |
| 5 | +const tmpdir = require('../common/tmpdir'); |
| 6 | + |
| 7 | +const { access, copyFile, open } = require('fs').promises; |
| 8 | +const path = require('path'); |
| 9 | + |
| 10 | +common.crashOnUnhandledRejection(); |
| 11 | + |
| 12 | +async function validateSync() { |
| 13 | + tmpdir.refresh(); |
| 14 | + const dest = path.resolve(tmpdir.path, 'baz.js'); |
| 15 | + await copyFile(fixtures.path('baz.js'), dest); |
| 16 | + await access(dest, 'r'); |
| 17 | + const handle = await open(dest, 'r+'); |
| 18 | + await handle.datasync(); |
| 19 | + await handle.sync(); |
| 20 | + const buf = Buffer.from('hello world'); |
| 21 | + await handle.write(buf); |
| 22 | + const ret = await handle.read(Buffer.alloc(11), 0, 11, 0); |
| 23 | + assert.strictEqual(ret.bytesRead, 11); |
| 24 | + assert.deepStrictEqual(ret.buffer, buf); |
| 25 | +} |
| 26 | + |
| 27 | +validateSync(); |