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