MCPcopy Index your code
hub / github.com/nodejs/node / test

Function test

test/parallel/test-fs-chmod-mask.js:22–86  ·  view source on GitHub ↗
(mode, asString)

Source from the content-addressed store, hash-verified

20tmpdir.refresh();
21
22function test(mode, asString) {
23 const suffix = asString ? 'str' : 'num';
24 const input = asString ?
25 (mode | maskToIgnore).toString(8) : (mode | maskToIgnore);
26
27 {
28 const file = tmpdir.resolve(`chmod-async-${suffix}.txt`);
29 fs.writeFileSync(file, 'test', 'utf-8');
30
31 fs.chmod(file, input, common.mustSucceed(() => {
32 assert.strictEqual(fs.statSync(file).mode & 0o777, mode);
33 }));
34 }
35
36 {
37 const file = tmpdir.resolve(`chmodSync-${suffix}.txt`);
38 fs.writeFileSync(file, 'test', 'utf-8');
39
40 fs.chmodSync(file, input);
41 assert.strictEqual(fs.statSync(file).mode & 0o777, mode);
42 }
43
44 {
45 const file = tmpdir.resolve(`fchmod-async-${suffix}.txt`);
46 fs.writeFileSync(file, 'test', 'utf-8');
47 fs.open(file, 'w', common.mustSucceed((fd) => {
48 fs.fchmod(fd, input, common.mustSucceed(() => {
49 assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode);
50 fs.close(fd, assert.ifError);
51 }));
52 }));
53 }
54
55 {
56 const file = tmpdir.resolve(`fchmodSync-${suffix}.txt`);
57 fs.writeFileSync(file, 'test', 'utf-8');
58 const fd = fs.openSync(file, 'w');
59
60 fs.fchmodSync(fd, input);
61 assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode);
62
63 fs.close(fd, assert.ifError);
64 }
65
66 if (fs.lchmod) {
67 const link = tmpdir.resolve(`lchmod-src-${suffix}`);
68 const file = tmpdir.resolve(`lchmod-dest-${suffix}`);
69 fs.writeFileSync(file, 'test', 'utf-8');
70 fs.symlinkSync(file, link);
71
72 fs.lchmod(link, input, common.mustSucceed(() => {
73 assert.strictEqual(fs.lstatSync(link).mode & 0o777, mode);
74 }));
75 }
76
77 if (fs.lchmodSync) {
78 const link = tmpdir.resolve(`lchmodSync-src-${suffix}`);
79 const file = tmpdir.resolve(`lchmodSync-dest-${suffix}`);

Callers 1

Calls 13

fstatSyncMethod · 0.80
lchmodMethod · 0.80
openMethod · 0.65
closeMethod · 0.65
toStringMethod · 0.45
resolveMethod · 0.45
writeFileSyncMethod · 0.45
chmodMethod · 0.45
statSyncMethod · 0.45
chmodSyncMethod · 0.45
openSyncMethod · 0.45
symlinkSyncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…