|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const fs = require('fs'); |
| 4 | + |
| 5 | +// This test ensures that input for fchmod is valid, testing for valid |
| 6 | +// inputs for fd and mode |
| 7 | + |
| 8 | +// Check input type |
| 9 | +['', false, null, undefined, {}, [], Infinity, -1].forEach((i) => { |
| 10 | + common.expectsError( |
| 11 | + () => fs.fchmod(i), |
| 12 | + { |
| 13 | + code: 'ERR_INVALID_ARG_TYPE', |
| 14 | + type: TypeError, |
| 15 | + message: 'The "fd" argument must be of type integer' |
| 16 | + } |
| 17 | + ); |
| 18 | + common.expectsError( |
| 19 | + () => fs.fchmodSync(i), |
| 20 | + { |
| 21 | + code: 'ERR_INVALID_ARG_TYPE', |
| 22 | + type: TypeError, |
| 23 | + message: 'The "fd" argument must be of type integer' |
| 24 | + } |
| 25 | + ); |
| 26 | + |
| 27 | + common.expectsError( |
| 28 | + () => fs.fchmod(1, i), |
| 29 | + { |
| 30 | + code: 'ERR_INVALID_ARG_TYPE', |
| 31 | + type: TypeError, |
| 32 | + message: 'The "mode" argument must be of type integer' |
| 33 | + } |
| 34 | + ); |
| 35 | + common.expectsError( |
| 36 | + () => fs.fchmodSync(1, i), |
| 37 | + { |
| 38 | + code: 'ERR_INVALID_ARG_TYPE', |
| 39 | + type: TypeError, |
| 40 | + message: 'The "mode" argument must be of type integer' |
| 41 | + } |
| 42 | + ); |
| 43 | +}); |
| 44 | + |
| 45 | +// Check for mode values range |
| 46 | +const modeUpperBoundaryValue = 0o777; |
| 47 | +fs.fchmod(1, modeUpperBoundaryValue); |
| 48 | +fs.fchmodSync(1, modeUpperBoundaryValue); |
| 49 | + |
| 50 | +// umask of 0o777 is equal to 775 |
| 51 | +const modeOutsideUpperBoundValue = 776; |
| 52 | +common.expectsError( |
| 53 | + () => fs.fchmod(1, modeOutsideUpperBoundValue), |
| 54 | + { |
| 55 | + code: 'ERR_OUT_OF_RANGE', |
| 56 | + type: RangeError, |
| 57 | + message: 'The value of "mode" is out of range.' |
| 58 | + } |
| 59 | +); |
| 60 | +common.expectsError( |
| 61 | + () => fs.fchmodSync(1, modeOutsideUpperBoundValue), |
| 62 | + { |
| 63 | + code: 'ERR_OUT_OF_RANGE', |
| 64 | + type: RangeError, |
| 65 | + message: 'The value of "mode" is out of range.' |
| 66 | + } |
| 67 | +); |
0 commit comments