Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixup! fixup! test: add known_issues test for fs.copyFile()
  • Loading branch information
Trott committed Mar 29, 2019
commit d15753a09333043db9af34ea3f119ce62eaa94d1
50 changes: 36 additions & 14 deletions test/known_issues/test-fs-copyfile-respect-permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,39 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');

const source = path.join(tmpdir.path, 'source');
const dest = path.join(tmpdir.path, 'dest');

fs.writeFileSync(source, 'source');
fs.writeFileSync(dest, 'dest');
fs.chmodSync(dest, '444');

assert.throws(() => { fs.copyFileSync(source, dest); },
{ code: 'EACCESS' });

fs.copyFile(source, dest, common.mustCall((err) => {
assert.strictEqual(err.code, 'EACCESS');
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'dest');
}));
let n = 0;

function beforeEach() {
n++;
const source = path.join(tmpdir.path, `source${n}`);
const dest = path.join(tmpdir.path, `dest${n}`);
fs.writeFileSync(source, 'source');
fs.writeFileSync(dest, 'dest');
fs.chmodSync(dest, '444');

const check = (err) => {
assert.strictEqual(err.code, 'EACCESS');
assert.strictEqual(fs.readFileSync(dest, 'utf8'), 'dest');
};

return { source, dest, check };
}

// Test synchronous API.
{
const { source, dest, check } = beforeEach();
assert.throws(() => { fs.copyFileSync(source, dest); }, check);
}

// Test promises API.
{
const { source, dest, check } = beforeEach();
assert.throws(async () => { await fs.promises.copyFile(source, dest); },
check);
}

// Test callback API.
{
const { source, dest, check } = beforeEach();
fs.copyFile(source, dest, common.mustCall(check));
}