1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5const fs = require('fs'); 6const { promises } = fs; 7const f = __filename; 8 9// This test ensures that input for lchmod is valid, testing for valid 10// inputs for path, mode and callback 11 12if (!common.isOSX) { 13 common.skip('lchmod is only available on macOS'); 14} 15 16// Check callback 17assert.throws(() => fs.lchmod(f), { code: 'ERR_INVALID_ARG_TYPE' }); 18assert.throws(() => fs.lchmod(), { code: 'ERR_INVALID_ARG_TYPE' }); 19assert.throws(() => fs.lchmod(f, {}), { code: 'ERR_INVALID_ARG_TYPE' }); 20 21// Check path 22[false, 1, {}, [], null, undefined].forEach((i) => { 23 assert.throws( 24 () => fs.lchmod(i, 0o777, common.mustNotCall()), 25 { 26 code: 'ERR_INVALID_ARG_TYPE', 27 name: 'TypeError' 28 } 29 ); 30 assert.throws( 31 () => fs.lchmodSync(i), 32 { 33 code: 'ERR_INVALID_ARG_TYPE', 34 name: 'TypeError' 35 } 36 ); 37}); 38 39// Check mode 40[false, null, {}, []].forEach((input) => { 41 const errObj = { 42 code: 'ERR_INVALID_ARG_TYPE', 43 }; 44 45 assert.rejects(promises.lchmod(f, input, () => {}), errObj); 46 assert.throws(() => fs.lchmodSync(f, input), errObj); 47}); 48 49assert.throws(() => fs.lchmod(f, '123x', common.mustNotCall()), { 50 code: 'ERR_INVALID_ARG_VALUE' 51}); 52assert.throws(() => fs.lchmodSync(f, '123x'), { 53 code: 'ERR_INVALID_ARG_VALUE' 54}); 55 56[-1, 2 ** 32].forEach((input) => { 57 const errObj = { 58 code: 'ERR_OUT_OF_RANGE', 59 name: 'RangeError', 60 message: 'The value of "mode" is out of range. It must be >= 0 && <= ' + 61 `4294967295. Received ${input}` 62 }; 63 64 assert.rejects(promises.lchmod(f, input, () => {}), errObj); 65 assert.throws(() => fs.lchmodSync(f, input), errObj); 66}); 67