| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 65392be commit 1b6dfac
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,67 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const util = require('util'); | ||
| 6 | + const fs = require('fs'); | ||
| 7 | + const { promises } = fs; | ||
| 8 | + const f = __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 | + const errObj = { | ||
| 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 | + const errObj = { | ||
| 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 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments