11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst fs = require('fs'); 61cb0ef41Sopenharmony_ciconst { promises } = fs; 71cb0ef41Sopenharmony_ciconst f = __filename; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci// This test ensures that input for lchmod is valid, testing for valid 101cb0ef41Sopenharmony_ci// inputs for path, mode and callback 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciif (!common.isOSX) { 131cb0ef41Sopenharmony_ci common.skip('lchmod is only available on macOS'); 141cb0ef41Sopenharmony_ci} 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci// Check callback 171cb0ef41Sopenharmony_ciassert.throws(() => fs.lchmod(f), { code: 'ERR_INVALID_ARG_TYPE' }); 181cb0ef41Sopenharmony_ciassert.throws(() => fs.lchmod(), { code: 'ERR_INVALID_ARG_TYPE' }); 191cb0ef41Sopenharmony_ciassert.throws(() => fs.lchmod(f, {}), { code: 'ERR_INVALID_ARG_TYPE' }); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci// Check path 221cb0ef41Sopenharmony_ci[false, 1, {}, [], null, undefined].forEach((i) => { 231cb0ef41Sopenharmony_ci assert.throws( 241cb0ef41Sopenharmony_ci () => fs.lchmod(i, 0o777, common.mustNotCall()), 251cb0ef41Sopenharmony_ci { 261cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 271cb0ef41Sopenharmony_ci name: 'TypeError' 281cb0ef41Sopenharmony_ci } 291cb0ef41Sopenharmony_ci ); 301cb0ef41Sopenharmony_ci assert.throws( 311cb0ef41Sopenharmony_ci () => fs.lchmodSync(i), 321cb0ef41Sopenharmony_ci { 331cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 341cb0ef41Sopenharmony_ci name: 'TypeError' 351cb0ef41Sopenharmony_ci } 361cb0ef41Sopenharmony_ci ); 371cb0ef41Sopenharmony_ci}); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci// Check mode 401cb0ef41Sopenharmony_ci[false, null, {}, []].forEach((input) => { 411cb0ef41Sopenharmony_ci const errObj = { 421cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 431cb0ef41Sopenharmony_ci }; 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci assert.rejects(promises.lchmod(f, input, () => {}), errObj); 461cb0ef41Sopenharmony_ci assert.throws(() => fs.lchmodSync(f, input), errObj); 471cb0ef41Sopenharmony_ci}); 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ciassert.throws(() => fs.lchmod(f, '123x', common.mustNotCall()), { 501cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_VALUE' 511cb0ef41Sopenharmony_ci}); 521cb0ef41Sopenharmony_ciassert.throws(() => fs.lchmodSync(f, '123x'), { 531cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_VALUE' 541cb0ef41Sopenharmony_ci}); 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci[-1, 2 ** 32].forEach((input) => { 571cb0ef41Sopenharmony_ci const errObj = { 581cb0ef41Sopenharmony_ci code: 'ERR_OUT_OF_RANGE', 591cb0ef41Sopenharmony_ci name: 'RangeError', 601cb0ef41Sopenharmony_ci message: 'The value of "mode" is out of range. It must be >= 0 && <= ' + 611cb0ef41Sopenharmony_ci `4294967295. Received ${input}` 621cb0ef41Sopenharmony_ci }; 631cb0ef41Sopenharmony_ci 641cb0ef41Sopenharmony_ci assert.rejects(promises.lchmod(f, input, () => {}), errObj); 651cb0ef41Sopenharmony_ci assert.throws(() => fs.lchmodSync(f, input), errObj); 661cb0ef41Sopenharmony_ci}); 67