11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_cirequire('../common');
41cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
51cb0ef41Sopenharmony_ciconst path = require('path');
61cb0ef41Sopenharmony_ciconst fs = require('fs');
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
101cb0ef41Sopenharmony_citmpdir.refresh();
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst streamOpts = ['open', 'close'];
131cb0ef41Sopenharmony_ciconst writeStreamOptions = [...streamOpts, 'write'];
141cb0ef41Sopenharmony_ciconst readStreamOptions = [...streamOpts, 'read'];
151cb0ef41Sopenharmony_ciconst originalFs = { fs };
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci{
181cb0ef41Sopenharmony_ci  const file = path.join(tmpdir.path, 'write-end-test0.txt');
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci  writeStreamOptions.forEach((fn) => {
211cb0ef41Sopenharmony_ci    const overrideFs = Object.assign({}, originalFs.fs, { [fn]: null });
221cb0ef41Sopenharmony_ci    if (fn === 'write') overrideFs.writev = null;
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci    const opts = {
251cb0ef41Sopenharmony_ci      fs: overrideFs
261cb0ef41Sopenharmony_ci    };
271cb0ef41Sopenharmony_ci    assert.throws(
281cb0ef41Sopenharmony_ci      () => fs.createWriteStream(file, opts), {
291cb0ef41Sopenharmony_ci        code: 'ERR_INVALID_ARG_TYPE',
301cb0ef41Sopenharmony_ci        name: 'TypeError',
311cb0ef41Sopenharmony_ci        message: `The "options.fs.${fn}" property must be of type function. ` +
321cb0ef41Sopenharmony_ci        'Received null'
331cb0ef41Sopenharmony_ci      },
341cb0ef41Sopenharmony_ci      `createWriteStream options.fs.${fn} should throw if isn't a function`
351cb0ef41Sopenharmony_ci    );
361cb0ef41Sopenharmony_ci  });
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci{
401cb0ef41Sopenharmony_ci  const file = path.join(tmpdir.path, 'write-end-test0.txt');
411cb0ef41Sopenharmony_ci  const overrideFs = Object.assign({}, originalFs.fs, { writev: 'not a fn' });
421cb0ef41Sopenharmony_ci  const opts = {
431cb0ef41Sopenharmony_ci    fs: overrideFs
441cb0ef41Sopenharmony_ci  };
451cb0ef41Sopenharmony_ci  assert.throws(
461cb0ef41Sopenharmony_ci    () => fs.createWriteStream(file, opts), {
471cb0ef41Sopenharmony_ci      code: 'ERR_INVALID_ARG_TYPE',
481cb0ef41Sopenharmony_ci      name: 'TypeError',
491cb0ef41Sopenharmony_ci      message: 'The "options.fs.writev" property must be of type function. ' +
501cb0ef41Sopenharmony_ci        'Received type string (\'not a fn\')'
511cb0ef41Sopenharmony_ci    },
521cb0ef41Sopenharmony_ci    'createWriteStream options.fs.writev should throw if isn\'t a function'
531cb0ef41Sopenharmony_ci  );
541cb0ef41Sopenharmony_ci}
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci{
571cb0ef41Sopenharmony_ci  const file = fixtures.path('x.txt');
581cb0ef41Sopenharmony_ci  readStreamOptions.forEach((fn) => {
591cb0ef41Sopenharmony_ci    const overrideFs = Object.assign({}, originalFs.fs, { [fn]: null });
601cb0ef41Sopenharmony_ci    const opts = {
611cb0ef41Sopenharmony_ci      fs: overrideFs
621cb0ef41Sopenharmony_ci    };
631cb0ef41Sopenharmony_ci    assert.throws(
641cb0ef41Sopenharmony_ci      () => fs.createReadStream(file, opts), {
651cb0ef41Sopenharmony_ci        code: 'ERR_INVALID_ARG_TYPE',
661cb0ef41Sopenharmony_ci        name: 'TypeError',
671cb0ef41Sopenharmony_ci        message: `The "options.fs.${fn}" property must be of type function. ` +
681cb0ef41Sopenharmony_ci        'Received null'
691cb0ef41Sopenharmony_ci      },
701cb0ef41Sopenharmony_ci      `createReadStream options.fs.${fn} should throw if isn't a function`
711cb0ef41Sopenharmony_ci    );
721cb0ef41Sopenharmony_ci  });
731cb0ef41Sopenharmony_ci}
74