test: add known_issues test for fs.copyFile() · nodejs/node@9330d7e (original) (raw)
``
1
`+
'use strict';
`
``
2
+
``
3
`+
// Test that fs.copyFile() respects file permissions.
`
``
4
`+
// Ref: https://github.com/nodejs/node/issues/26936
`
``
5
+
``
6
`+
const common = require('../common');
`
``
7
+
``
8
`+
const tmpdir = require('../common/tmpdir');
`
``
9
`+
tmpdir.refresh();
`
``
10
+
``
11
`+
const assert = require('assert');
`
``
12
`+
const fs = require('fs');
`
``
13
`+
const path = require('path');
`
``
14
+
``
15
`+
let n = 0;
`
``
16
+
``
17
`+
function beforeEach() {
`
``
18
`+
n++;
`
``
19
`` +
const source = path.join(tmpdir.path, source${n}
);
``
``
20
`` +
const dest = path.join(tmpdir.path, dest${n}
);
``
``
21
`+
fs.writeFileSync(source, 'source');
`
``
22
`+
fs.writeFileSync(dest, 'dest');
`
``
23
`+
fs.chmodSync(dest, '444');
`
``
24
+
``
25
`+
const check = (err) => {
`
``
26
`+
assert.strictEqual(err.code, 'EACCESS');
`
``
27
`+
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'dest');
`
``
28
`+
};
`
``
29
+
``
30
`+
return { source, dest, check };
`
``
31
`+
}
`
``
32
+
``
33
`+
// Test synchronous API.
`
``
34
`+
{
`
``
35
`+
const { source, dest, check } = beforeEach();
`
``
36
`+
assert.throws(() => { fs.copyFileSync(source, dest); }, check);
`
``
37
`+
}
`
``
38
+
``
39
`+
// Test promises API.
`
``
40
`+
{
`
``
41
`+
const { source, dest, check } = beforeEach();
`
``
42
`+
assert.throws(async () => { await fs.promises.copyFile(source, dest); },
`
``
43
`+
check);
`
``
44
`+
}
`
``
45
+
``
46
`+
// Test callback API.
`
``
47
`+
{
`
``
48
`+
const { source, dest, check } = beforeEach();
`
``
49
`+
fs.copyFile(source, dest, common.mustCall(check));
`
``
50
`+
}
`