GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: add test for fs.lchmod · nodejs/node@3afb481

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-fs-lchmod.js
Expand file treeCollapse file tree
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.