11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
51cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst { access, copyFile, open } = require('fs').promises;
81cb0ef41Sopenharmony_ciconst path = require('path');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciasync function validate() {
111cb0ef41Sopenharmony_ci  tmpdir.refresh();
121cb0ef41Sopenharmony_ci  const dest = path.resolve(tmpdir.path, 'baz.js');
131cb0ef41Sopenharmony_ci  await assert.rejects(
141cb0ef41Sopenharmony_ci    copyFile(fixtures.path('baz.js'), dest, 'r'),
151cb0ef41Sopenharmony_ci    {
161cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_ARG_TYPE',
171cb0ef41Sopenharmony_ci    }
181cb0ef41Sopenharmony_ci  );
191cb0ef41Sopenharmony_ci  await copyFile(fixtures.path('baz.js'), dest);
201cb0ef41Sopenharmony_ci  await assert.rejects(
211cb0ef41Sopenharmony_ci    access(dest, 'r'),
221cb0ef41Sopenharmony_ci    { code: 'ERR_INVALID_ARG_TYPE', message: /mode/ }
231cb0ef41Sopenharmony_ci  );
241cb0ef41Sopenharmony_ci  await access(dest);
251cb0ef41Sopenharmony_ci  const handle = await open(dest, 'r+');
261cb0ef41Sopenharmony_ci  await handle.datasync();
271cb0ef41Sopenharmony_ci  await handle.sync();
281cb0ef41Sopenharmony_ci  const buf = Buffer.from('hello world');
291cb0ef41Sopenharmony_ci  await handle.write(buf);
301cb0ef41Sopenharmony_ci  const ret = await handle.read(Buffer.alloc(11), 0, 11, 0);
311cb0ef41Sopenharmony_ci  assert.strictEqual(ret.bytesRead, 11);
321cb0ef41Sopenharmony_ci  assert.deepStrictEqual(ret.buffer, buf);
331cb0ef41Sopenharmony_ci  await handle.close();
341cb0ef41Sopenharmony_ci}
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_civalidate();
37