Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3afb481

Browse filesBrowse files
ZYSzysaddaleax
authored andcommitted
test: add test for fs.lchmod
PR-URL: #25439 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 57a0cd4 commit 3afb481
Copy full SHA for 3afb481

File tree

Expand file treeCollapse file tree

1 file changed

+67
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+67
-0
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-fs-lchmod.js‎

Copy file name to clipboard
+67Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.