Skip to content

Commit

Permalink
fix: using utils.pathJoin instead of path.join for tests
Browse files Browse the repository at this point in the history
Using `path.join` caused the tests to use the windows' separator for the path which is not supported by the EFS. This lead to a lot of test failures.

#69
  • Loading branch information
tegefaulkes committed Jul 28, 2022
1 parent 442a61f commit 6bb853a
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 222 deletions.
133 changes: 66 additions & 67 deletions tests/EncryptedFS.concurrent.test.ts

Large diffs are not rendered by default.

161 changes: 80 additions & 81 deletions tests/EncryptedFS.dirs.test.ts

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions tests/EncryptedFS.files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { FileTypes } from './utils';
import os from 'os';
import fs from 'fs';
import pathNode from 'path';
import path from 'path';
import Logger, { StreamHandler, LogLevel } from '@matrixai/logger';
import { code as errno } from 'errno';
import EncryptedFS from '@/EncryptedFS';
Expand Down Expand Up @@ -199,7 +198,7 @@ describe(`${EncryptedFS.name} Files`, () => {
await efs.close(fd);
});
test('truncates the file contents', async () => {
const path1 = path.join('dir', 'path1');
const path1 = utils.pathJoin('dir', 'path1');
await efs.mkdir('dir');
await efs.writeFile(path1, 'abcdef');
expect(await efs.readFile(path1, { encoding: 'utf-8' })).toEqual(
Expand Down Expand Up @@ -502,7 +501,7 @@ describe(`${EncryptedFS.name} Files`, () => {
await efs.close(fd);
});
test("updates parent directory ctime/mtime if file didn't exist", async () => {
const PUT = path.join(n1, n0);
const PUT = utils.pathJoin(n1, n0);
await efs.mkdir(n1, { mode: dp });
const time = (await efs.stat(n1)).ctime.getTime();
await sleep(10);
Expand All @@ -519,7 +518,7 @@ describe(`${EncryptedFS.name} Files`, () => {
expect(time).toBeLessThan(ctime2);
});
test("doesn't update parent directory ctime/mtime if file existed", async () => {
const PUT = path.join(n1, n0);
const PUT = utils.pathJoin(n1, n0);
await efs.mkdir(n1, { mode: dp });

await createFile(efs, 'regular', PUT);
Expand All @@ -541,7 +540,7 @@ describe(`${EncryptedFS.name} Files`, () => {
test.each(['regular', 'block'])(
'returns ENOTDIR if a component of the path prefix is a %s',
async (type) => {
const PUT = path.join(n1, 'test');
const PUT = utils.pathJoin(n1, 'test');
await createFile(efs, type as FileTypes, n1);
await expectError(
efs.open(PUT, 'r'),
Expand All @@ -558,12 +557,12 @@ describe(`${EncryptedFS.name} Files`, () => {
test('returns ENOENT if a component of the path name that must exist does not exist or O_CREAT is not set and the named file does not exist', async () => {
await efs.mkdir(n0, { mode: dp });
await expectError(
efs.open(path.join(n0, n1, 'test'), constants.O_CREAT, 0o0644),
efs.open(utils.pathJoin(n0, n1, 'test'), constants.O_CREAT, 0o0644),
ErrorEncryptedFSError,
errno.ENOENT,
);
await expectError(
efs.open(path.join(n0, n1, 'test'), constants.O_RDONLY),
efs.open(utils.pathJoin(n0, n1, 'test'), constants.O_RDONLY),
ErrorEncryptedFSError,
errno.ENOENT,
);
Expand All @@ -572,17 +571,17 @@ describe(`${EncryptedFS.name} Files`, () => {
await efs.mkdir(n1, { mode: dp });
await efs.chown(n1, tuid, tuid);
setId(efs, tuid);
await createFile(efs, 'regular', path.join(n1, n2));
let fd = await efs.open(path.join(n1, n2), constants.O_RDONLY);
await createFile(efs, 'regular', utils.pathJoin(n1, n2));
let fd = await efs.open(utils.pathJoin(n1, n2), constants.O_RDONLY);
await efs.close(fd);
await efs.chmod(n1, 0o0644);
await expectError(
efs.open(path.join(n1, n2), constants.O_RDONLY),
efs.open(utils.pathJoin(n1, n2), constants.O_RDONLY),
ErrorEncryptedFSError,
errno.EACCES,
);
await efs.chmod(n1, 0o0755);
fd = await efs.open(path.join(n1, n2), constants.O_RDONLY);
fd = await efs.open(utils.pathJoin(n1, n2), constants.O_RDONLY);
await efs.close(fd);
});
test('returns EACCES when the required permissions are denied for a regular file', async () => {
Expand Down Expand Up @@ -854,12 +853,12 @@ describe(`${EncryptedFS.name} Files`, () => {
await efs.symlink(n0, n1);
await efs.symlink(n1, n0);
await expectError(
efs.open(path.join(n0, 'test'), constants.O_RDONLY),
efs.open(utils.pathJoin(n0, 'test'), constants.O_RDONLY),
ErrorEncryptedFSError,
errno.ELOOP,
);
await expectError(
efs.open(path.join(n1, 'test'), constants.O_RDONLY),
efs.open(utils.pathJoin(n1, 'test'), constants.O_RDONLY),
ErrorEncryptedFSError,
errno.ELOOP,
);
Expand Down
81 changes: 40 additions & 41 deletions tests/EncryptedFS.links.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { FileTypes } from './utils';
import os from 'os';
import fs from 'fs';
import pathNode from 'path';
import path from 'path';
import Logger, { StreamHandler, LogLevel } from '@matrixai/logger';
import { code as errno } from 'errno';
import EncryptedFS from '@/EncryptedFS';
Expand Down Expand Up @@ -71,7 +70,7 @@ describe(`${EncryptedFS.name} Links`, () => {
let stat2 = await efs.stat(n0);
const time = stat2.birthtime.getTime();
await sleep(100);
await efs.symlink('test', path.join(n0, n1));
await efs.symlink('test', utils.pathJoin(n0, n1));
stat2 = await efs.stat(n0);
const mtime = stat2.mtime.getTime();
const ctime = stat2.ctime.getTime();
Expand Down Expand Up @@ -151,49 +150,49 @@ describe(`${EncryptedFS.name} Links`, () => {
await efs.mkdir(n1, { mode: dp });
await efs.chown(n1, tuid, tuid);

await efs.symlink('test', path.join(n1, n2));
await efs.unlink(path.join(n1, n2));
await efs.symlink('test', utils.pathJoin(n1, n2));
await efs.unlink(utils.pathJoin(n1, n2));

await efs.chmod(n1, 0o0644);
setId(efs, tuid);
await expectError(
efs.symlink('test', path.join(n1, n2)),
efs.symlink('test', utils.pathJoin(n1, n2)),
ErrorEncryptedFSError,
errno.EACCES,
);
await efs.chmod(n1, dp);
await efs.symlink('test', path.join(n1, n2));
await efs.unlink(path.join(n1, n2));
await efs.symlink('test', utils.pathJoin(n1, n2));
await efs.unlink(utils.pathJoin(n1, n2));
});
test('returns EACCES if the parent directory of the file to be created denies write permission', async () => {
await efs.mkdir(n1, { mode: dp });
await efs.chown(n1, tuid, tuid);

setId(efs, tuid);
await efs.symlink('test', path.join(n1, n2));
await efs.unlink(path.join(n1, n2));
await efs.symlink('test', utils.pathJoin(n1, n2));
await efs.unlink(utils.pathJoin(n1, n2));

await efs.chmod(n1, 0o0555);
setId(efs, tuid);
await expectError(
efs.symlink('test', path.join(n1, n2)),
efs.symlink('test', utils.pathJoin(n1, n2)),
ErrorEncryptedFSError,
errno.EACCES,
);
await efs.chmod(n1, 0o0755);
await efs.symlink('test', path.join(n1, n2));
await efs.unlink(path.join(n1, n2));
await efs.symlink('test', utils.pathJoin(n1, n2));
await efs.unlink(utils.pathJoin(n1, n2));
});
test('returns ELOOP if too many symbolic links were encountered in translating the name2 path name', async () => {
await efs.symlink(n0, n1);
await efs.symlink(n1, n0);
await expectError(
efs.symlink('test', path.join(n0, 'test')),
efs.symlink('test', utils.pathJoin(n0, 'test')),
ErrorEncryptedFSError,
errno.ELOOP,
);
await expectError(
efs.symlink('test', path.join(n1, 'test')),
efs.symlink('test', utils.pathJoin(n1, 'test')),
ErrorEncryptedFSError,
errno.ELOOP,
);
Expand Down Expand Up @@ -254,9 +253,9 @@ describe(`${EncryptedFS.name} Links`, () => {
});
test('returns ENOTDIR if a component of the path prefix is not a directory', async () => {
await efs.mkdir(n0, { mode: dp });
await createFile(efs, 'regular', path.join(n0, n1));
await createFile(efs, 'regular', utils.pathJoin(n0, n1));
await expectError(
efs.unlink(path.join(n0, n1, 'test')),
efs.unlink(utils.pathJoin(n0, n1, 'test')),
ErrorEncryptedFSError,
errno.ENOTDIR,
);
Expand All @@ -271,10 +270,10 @@ describe(`${EncryptedFS.name} Links`, () => {
await efs.mkdir(n1, { mode: dp });
await efs.chown(n1, tuid, tuid);
setId(efs, tuid);
await createFile(efs, 'regular', path.join(n1, n2));
await createFile(efs, 'regular', utils.pathJoin(n1, n2));
await efs.chmod(n1, 0o0644);
await expectError(
efs.unlink(path.join(n1, n2)),
efs.unlink(utils.pathJoin(n1, n2)),
ErrorEncryptedFSError,
errno.EACCES,
);
Expand All @@ -283,10 +282,10 @@ describe(`${EncryptedFS.name} Links`, () => {
await efs.mkdir(n1, { mode: dp });
await efs.chown(n1, tuid, tuid);
setId(efs, tuid);
await createFile(efs, 'regular', path.join(n1, n2));
await createFile(efs, 'regular', utils.pathJoin(n1, n2));
await efs.chmod(n1, 0o0555);
await expectError(
efs.unlink(path.join(n1, n2)),
efs.unlink(utils.pathJoin(n1, n2)),
ErrorEncryptedFSError,
errno.EACCES,
);
Expand All @@ -295,12 +294,12 @@ describe(`${EncryptedFS.name} Links`, () => {
await efs.symlink(n0, n1);
await efs.symlink(n1, n0);
await expectError(
efs.unlink(path.join(n0, 'test')),
efs.unlink(utils.pathJoin(n0, 'test')),
ErrorEncryptedFSError,
errno.ELOOP,
);
await expectError(
efs.unlink(path.join(n1, 'test')),
efs.unlink(utils.pathJoin(n1, 'test')),
ErrorEncryptedFSError,
errno.ELOOP,
);
Expand Down Expand Up @@ -451,15 +450,15 @@ describe(`${EncryptedFS.name} Links`, () => {
async (type) => {
if (type !== 'dir' && type !== 'symlink') {
await efs.mkdir(n0, { mode: dp });
await createFile(efs, type as FileTypes, path.join(n0, n1));
await createFile(efs, type as FileTypes, utils.pathJoin(n0, n1));
await expectError(
efs.link(path.join(n0, n1, 'test'), path.join(n0, n2)),
efs.link(utils.pathJoin(n0, n1, 'test'), utils.pathJoin(n0, n2)),
ErrorEncryptedFSError,
errno.ENOTDIR,
);
await createFile(efs, type as FileTypes, path.join(n0, n2));
await createFile(efs, type as FileTypes, utils.pathJoin(n0, n2));
await expectError(
efs.link(path.join(n0, n2), path.join(n0, n1, 'test')),
efs.link(utils.pathJoin(n0, n2), utils.pathJoin(n0, n1, 'test')),
ErrorEncryptedFSError,
errno.ENOTDIR,
);
Expand All @@ -472,24 +471,24 @@ describe(`${EncryptedFS.name} Links`, () => {
await efs.mkdir(n2, { mode: dp });
await efs.chown(n2, tuid, tuid);
setId(efs, tuid);
await createFile(efs, 'regular', path.join(n1, n3));
await efs.link(path.join(n1, n3), path.join(n2, n4));
await efs.unlink(path.join(n2, n4));
await createFile(efs, 'regular', utils.pathJoin(n1, n3));
await efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4));
await efs.unlink(utils.pathJoin(n2, n4));
await efs.chmod(n1, 0o0644);
await expectError(
efs.link(path.join(n1, n3), path.join(n1, n4)),
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n1, n4)),
ErrorEncryptedFSError,
errno.EACCES,
);
await expectError(
efs.link(path.join(n1, n3), path.join(n2, n4)),
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4)),
ErrorEncryptedFSError,
errno.EACCES,
);
await efs.chmod(n1, 0o0755);
await efs.chmod(n2, 0o0644);
await expectError(
efs.link(path.join(n1, n3), path.join(n2, n4)),
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4)),
ErrorEncryptedFSError,
errno.EACCES,
);
Expand All @@ -500,20 +499,20 @@ describe(`${EncryptedFS.name} Links`, () => {
await efs.mkdir(n2, { mode: dp });
await efs.chown(n2, tuid, tuid);
setId(efs, tuid);
await createFile(efs, 'regular', path.join(n1, n3));
await createFile(efs, 'regular', utils.pathJoin(n1, n3));

await efs.link(path.join(n1, n3), path.join(n2, n4));
await efs.unlink(path.join(n2, n4));
await efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4));
await efs.unlink(utils.pathJoin(n2, n4));

await efs.chmod(n2, 0o0555);
await expectError(
efs.link(path.join(n1, n3), path.join(n2, n4)),
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4)),
ErrorEncryptedFSError,
errno.EACCES,
);
await efs.chmod(n1, 0o0555);
await expectError(
efs.link(path.join(n1, n3), path.join(n1, n4)),
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n1, n4)),
ErrorEncryptedFSError,
errno.EACCES,
);
Expand All @@ -522,23 +521,23 @@ describe(`${EncryptedFS.name} Links`, () => {
await efs.symlink(n0, n1);
await efs.symlink(n1, n0);
await expectError(
efs.link(path.join(n0, 'test'), n2),
efs.link(utils.pathJoin(n0, 'test'), n2),
ErrorEncryptedFSError,
errno.ELOOP,
);
await expectError(
efs.link(path.join(n1, 'test'), n2),
efs.link(utils.pathJoin(n1, 'test'), n2),
ErrorEncryptedFSError,
errno.ELOOP,
);
await createFile(efs, 'regular', n2);
await expectError(
efs.link(n2, path.join(n0, 'test')),
efs.link(n2, utils.pathJoin(n0, 'test')),
ErrorEncryptedFSError,
errno.ELOOP,
);
await expectError(
efs.link(n2, path.join(n1, 'test')),
efs.link(n2, utils.pathJoin(n1, 'test')),
ErrorEncryptedFSError,
errno.ELOOP,
);
Expand Down
16 changes: 8 additions & 8 deletions tests/EncryptedFS.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os from 'os';
import path from 'path';
import fs from 'fs';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import EncryptedFS from '@/EncryptedFS';
Expand All @@ -14,7 +13,7 @@ describe(EncryptedFS.name, () => {
let dataDir: string;
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
path.join(os.tmpdir(), 'encryptedfs-test-'),
utils.pathJoin(os.tmpdir(), 'encryptedfs-test-'),
);
});
afterEach(async () => {
Expand Down Expand Up @@ -119,13 +118,13 @@ describe(EncryptedFS.name, () => {
});
test('iNode allocation across restarts', async () => {
const d1 = 'dir1';
const d1f1 = path.join(d1, 'file1');
const d1f2 = path.join(d1, 'file2');
const d1f3 = path.join(d1, 'file3');
const d1f1 = utils.pathJoin(d1, 'file1');
const d1f2 = utils.pathJoin(d1, 'file2');
const d1f3 = utils.pathJoin(d1, 'file3');
const d2 = 'dir2';
const d2f1 = path.join(d2, 'file1');
const d2f2 = path.join(d2, 'file2');
const d2f3 = path.join(d2, 'file3');
const d2f1 = utils.pathJoin(d2, 'file1');
const d2f2 = utils.pathJoin(d2, 'file2');
const d2f3 = utils.pathJoin(d2, 'file3');

let efs = await EncryptedFS.createEncryptedFS({
dbPath: dataDir,
Expand Down Expand Up @@ -178,5 +177,6 @@ describe(EncryptedFS.name, () => {
expect(await listNodes(efs)).toEqual([1, 3, 4, 5, 6, 7, 8, 9, 10]);
// Note that 2 is skipped, this seems to be incremented
// but not created when the RFS is created
await efs.stop();
});
});
3 changes: 1 addition & 2 deletions tests/fd/FileDescriptor.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os from 'os';
import path from 'path';
import fs from 'fs';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import { DB } from '@matrixai/db';
Expand All @@ -22,7 +21,7 @@ describe('File Descriptor', () => {
const origBuffer = Buffer.from('Test Buffer for File Descriptor');
beforeEach(async () => {
dataDir = await fs.promises.mkdtemp(
path.join(os.tmpdir(), 'encryptedfs-test-'),
utils.pathJoin(os.tmpdir(), 'encryptedfs-test-'),
);
db = await DB.createDB({
dbPath: `${dataDir}/db`,
Expand Down
Loading

0 comments on commit 6bb853a

Please sign in to comment.