Skip to content

Commit 0084570

Browse files
committed
fix: using utils.pathJoin instead of path.join for tests
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
1 parent db877c9 commit 0084570

11 files changed

+212
-222
lines changed

tests/EncryptedFS.concurrent.test.ts

+66-67
Large diffs are not rendered by default.

tests/EncryptedFS.dirs.test.ts

+80-81
Large diffs are not rendered by default.

tests/EncryptedFS.files.test.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { FileTypes } from './utils';
22
import os from 'os';
33
import fs from 'fs';
44
import pathNode from 'path';
5-
import path from 'path';
65
import Logger, { StreamHandler, LogLevel } from '@matrixai/logger';
76
import { code as errno } from 'errno';
87
import EncryptedFS from '@/EncryptedFS';
@@ -199,7 +198,7 @@ describe(`${EncryptedFS.name} Files`, () => {
199198
await efs.close(fd);
200199
});
201200
test('truncates the file contents', async () => {
202-
const path1 = path.join('dir', 'path1');
201+
const path1 = utils.pathJoin('dir', 'path1');
203202
await efs.mkdir('dir');
204203
await efs.writeFile(path1, 'abcdef');
205204
expect(await efs.readFile(path1, { encoding: 'utf-8' })).toEqual(
@@ -502,7 +501,7 @@ describe(`${EncryptedFS.name} Files`, () => {
502501
await efs.close(fd);
503502
});
504503
test("updates parent directory ctime/mtime if file didn't exist", async () => {
505-
const PUT = path.join(n1, n0);
504+
const PUT = utils.pathJoin(n1, n0);
506505
await efs.mkdir(n1, { mode: dp });
507506
const time = (await efs.stat(n1)).ctime.getTime();
508507
await sleep(10);
@@ -519,7 +518,7 @@ describe(`${EncryptedFS.name} Files`, () => {
519518
expect(time).toBeLessThan(ctime2);
520519
});
521520
test("doesn't update parent directory ctime/mtime if file existed", async () => {
522-
const PUT = path.join(n1, n0);
521+
const PUT = utils.pathJoin(n1, n0);
523522
await efs.mkdir(n1, { mode: dp });
524523

525524
await createFile(efs, 'regular', PUT);
@@ -541,7 +540,7 @@ describe(`${EncryptedFS.name} Files`, () => {
541540
test.each(['regular', 'block'])(
542541
'returns ENOTDIR if a component of the path prefix is a %s',
543542
async (type) => {
544-
const PUT = path.join(n1, 'test');
543+
const PUT = utils.pathJoin(n1, 'test');
545544
await createFile(efs, type as FileTypes, n1);
546545
await expectError(
547546
efs.open(PUT, 'r'),
@@ -558,12 +557,12 @@ describe(`${EncryptedFS.name} Files`, () => {
558557
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 () => {
559558
await efs.mkdir(n0, { mode: dp });
560559
await expectError(
561-
efs.open(path.join(n0, n1, 'test'), constants.O_CREAT, 0o0644),
560+
efs.open(utils.pathJoin(n0, n1, 'test'), constants.O_CREAT, 0o0644),
562561
ErrorEncryptedFSError,
563562
errno.ENOENT,
564563
);
565564
await expectError(
566-
efs.open(path.join(n0, n1, 'test'), constants.O_RDONLY),
565+
efs.open(utils.pathJoin(n0, n1, 'test'), constants.O_RDONLY),
567566
ErrorEncryptedFSError,
568567
errno.ENOENT,
569568
);
@@ -572,17 +571,17 @@ describe(`${EncryptedFS.name} Files`, () => {
572571
await efs.mkdir(n1, { mode: dp });
573572
await efs.chown(n1, tuid, tuid);
574573
setId(efs, tuid);
575-
await createFile(efs, 'regular', path.join(n1, n2));
576-
let fd = await efs.open(path.join(n1, n2), constants.O_RDONLY);
574+
await createFile(efs, 'regular', utils.pathJoin(n1, n2));
575+
let fd = await efs.open(utils.pathJoin(n1, n2), constants.O_RDONLY);
577576
await efs.close(fd);
578577
await efs.chmod(n1, 0o0644);
579578
await expectError(
580-
efs.open(path.join(n1, n2), constants.O_RDONLY),
579+
efs.open(utils.pathJoin(n1, n2), constants.O_RDONLY),
581580
ErrorEncryptedFSError,
582581
errno.EACCES,
583582
);
584583
await efs.chmod(n1, 0o0755);
585-
fd = await efs.open(path.join(n1, n2), constants.O_RDONLY);
584+
fd = await efs.open(utils.pathJoin(n1, n2), constants.O_RDONLY);
586585
await efs.close(fd);
587586
});
588587
test('returns EACCES when the required permissions are denied for a regular file', async () => {
@@ -854,12 +853,12 @@ describe(`${EncryptedFS.name} Files`, () => {
854853
await efs.symlink(n0, n1);
855854
await efs.symlink(n1, n0);
856855
await expectError(
857-
efs.open(path.join(n0, 'test'), constants.O_RDONLY),
856+
efs.open(utils.pathJoin(n0, 'test'), constants.O_RDONLY),
858857
ErrorEncryptedFSError,
859858
errno.ELOOP,
860859
);
861860
await expectError(
862-
efs.open(path.join(n1, 'test'), constants.O_RDONLY),
861+
efs.open(utils.pathJoin(n1, 'test'), constants.O_RDONLY),
863862
ErrorEncryptedFSError,
864863
errno.ELOOP,
865864
);

tests/EncryptedFS.links.test.ts

+40-41
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { FileTypes } from './utils';
22
import os from 'os';
33
import fs from 'fs';
44
import pathNode from 'path';
5-
import path from 'path';
65
import Logger, { StreamHandler, LogLevel } from '@matrixai/logger';
76
import { code as errno } from 'errno';
87
import EncryptedFS from '@/EncryptedFS';
@@ -71,7 +70,7 @@ describe(`${EncryptedFS.name} Links`, () => {
7170
let stat2 = await efs.stat(n0);
7271
const time = stat2.birthtime.getTime();
7372
await sleep(100);
74-
await efs.symlink('test', path.join(n0, n1));
73+
await efs.symlink('test', utils.pathJoin(n0, n1));
7574
stat2 = await efs.stat(n0);
7675
const mtime = stat2.mtime.getTime();
7776
const ctime = stat2.ctime.getTime();
@@ -151,49 +150,49 @@ describe(`${EncryptedFS.name} Links`, () => {
151150
await efs.mkdir(n1, { mode: dp });
152151
await efs.chown(n1, tuid, tuid);
153152

154-
await efs.symlink('test', path.join(n1, n2));
155-
await efs.unlink(path.join(n1, n2));
153+
await efs.symlink('test', utils.pathJoin(n1, n2));
154+
await efs.unlink(utils.pathJoin(n1, n2));
156155

157156
await efs.chmod(n1, 0o0644);
158157
setId(efs, tuid);
159158
await expectError(
160-
efs.symlink('test', path.join(n1, n2)),
159+
efs.symlink('test', utils.pathJoin(n1, n2)),
161160
ErrorEncryptedFSError,
162161
errno.EACCES,
163162
);
164163
await efs.chmod(n1, dp);
165-
await efs.symlink('test', path.join(n1, n2));
166-
await efs.unlink(path.join(n1, n2));
164+
await efs.symlink('test', utils.pathJoin(n1, n2));
165+
await efs.unlink(utils.pathJoin(n1, n2));
167166
});
168167
test('returns EACCES if the parent directory of the file to be created denies write permission', async () => {
169168
await efs.mkdir(n1, { mode: dp });
170169
await efs.chown(n1, tuid, tuid);
171170

172171
setId(efs, tuid);
173-
await efs.symlink('test', path.join(n1, n2));
174-
await efs.unlink(path.join(n1, n2));
172+
await efs.symlink('test', utils.pathJoin(n1, n2));
173+
await efs.unlink(utils.pathJoin(n1, n2));
175174

176175
await efs.chmod(n1, 0o0555);
177176
setId(efs, tuid);
178177
await expectError(
179-
efs.symlink('test', path.join(n1, n2)),
178+
efs.symlink('test', utils.pathJoin(n1, n2)),
180179
ErrorEncryptedFSError,
181180
errno.EACCES,
182181
);
183182
await efs.chmod(n1, 0o0755);
184-
await efs.symlink('test', path.join(n1, n2));
185-
await efs.unlink(path.join(n1, n2));
183+
await efs.symlink('test', utils.pathJoin(n1, n2));
184+
await efs.unlink(utils.pathJoin(n1, n2));
186185
});
187186
test('returns ELOOP if too many symbolic links were encountered in translating the name2 path name', async () => {
188187
await efs.symlink(n0, n1);
189188
await efs.symlink(n1, n0);
190189
await expectError(
191-
efs.symlink('test', path.join(n0, 'test')),
190+
efs.symlink('test', utils.pathJoin(n0, 'test')),
192191
ErrorEncryptedFSError,
193192
errno.ELOOP,
194193
);
195194
await expectError(
196-
efs.symlink('test', path.join(n1, 'test')),
195+
efs.symlink('test', utils.pathJoin(n1, 'test')),
197196
ErrorEncryptedFSError,
198197
errno.ELOOP,
199198
);
@@ -254,9 +253,9 @@ describe(`${EncryptedFS.name} Links`, () => {
254253
});
255254
test('returns ENOTDIR if a component of the path prefix is not a directory', async () => {
256255
await efs.mkdir(n0, { mode: dp });
257-
await createFile(efs, 'regular', path.join(n0, n1));
256+
await createFile(efs, 'regular', utils.pathJoin(n0, n1));
258257
await expectError(
259-
efs.unlink(path.join(n0, n1, 'test')),
258+
efs.unlink(utils.pathJoin(n0, n1, 'test')),
260259
ErrorEncryptedFSError,
261260
errno.ENOTDIR,
262261
);
@@ -271,10 +270,10 @@ describe(`${EncryptedFS.name} Links`, () => {
271270
await efs.mkdir(n1, { mode: dp });
272271
await efs.chown(n1, tuid, tuid);
273272
setId(efs, tuid);
274-
await createFile(efs, 'regular', path.join(n1, n2));
273+
await createFile(efs, 'regular', utils.pathJoin(n1, n2));
275274
await efs.chmod(n1, 0o0644);
276275
await expectError(
277-
efs.unlink(path.join(n1, n2)),
276+
efs.unlink(utils.pathJoin(n1, n2)),
278277
ErrorEncryptedFSError,
279278
errno.EACCES,
280279
);
@@ -283,10 +282,10 @@ describe(`${EncryptedFS.name} Links`, () => {
283282
await efs.mkdir(n1, { mode: dp });
284283
await efs.chown(n1, tuid, tuid);
285284
setId(efs, tuid);
286-
await createFile(efs, 'regular', path.join(n1, n2));
285+
await createFile(efs, 'regular', utils.pathJoin(n1, n2));
287286
await efs.chmod(n1, 0o0555);
288287
await expectError(
289-
efs.unlink(path.join(n1, n2)),
288+
efs.unlink(utils.pathJoin(n1, n2)),
290289
ErrorEncryptedFSError,
291290
errno.EACCES,
292291
);
@@ -295,12 +294,12 @@ describe(`${EncryptedFS.name} Links`, () => {
295294
await efs.symlink(n0, n1);
296295
await efs.symlink(n1, n0);
297296
await expectError(
298-
efs.unlink(path.join(n0, 'test')),
297+
efs.unlink(utils.pathJoin(n0, 'test')),
299298
ErrorEncryptedFSError,
300299
errno.ELOOP,
301300
);
302301
await expectError(
303-
efs.unlink(path.join(n1, 'test')),
302+
efs.unlink(utils.pathJoin(n1, 'test')),
304303
ErrorEncryptedFSError,
305304
errno.ELOOP,
306305
);
@@ -451,15 +450,15 @@ describe(`${EncryptedFS.name} Links`, () => {
451450
async (type) => {
452451
if (type !== 'dir' && type !== 'symlink') {
453452
await efs.mkdir(n0, { mode: dp });
454-
await createFile(efs, type as FileTypes, path.join(n0, n1));
453+
await createFile(efs, type as FileTypes, utils.pathJoin(n0, n1));
455454
await expectError(
456-
efs.link(path.join(n0, n1, 'test'), path.join(n0, n2)),
455+
efs.link(utils.pathJoin(n0, n1, 'test'), utils.pathJoin(n0, n2)),
457456
ErrorEncryptedFSError,
458457
errno.ENOTDIR,
459458
);
460-
await createFile(efs, type as FileTypes, path.join(n0, n2));
459+
await createFile(efs, type as FileTypes, utils.pathJoin(n0, n2));
461460
await expectError(
462-
efs.link(path.join(n0, n2), path.join(n0, n1, 'test')),
461+
efs.link(utils.pathJoin(n0, n2), utils.pathJoin(n0, n1, 'test')),
463462
ErrorEncryptedFSError,
464463
errno.ENOTDIR,
465464
);
@@ -472,24 +471,24 @@ describe(`${EncryptedFS.name} Links`, () => {
472471
await efs.mkdir(n2, { mode: dp });
473472
await efs.chown(n2, tuid, tuid);
474473
setId(efs, tuid);
475-
await createFile(efs, 'regular', path.join(n1, n3));
476-
await efs.link(path.join(n1, n3), path.join(n2, n4));
477-
await efs.unlink(path.join(n2, n4));
474+
await createFile(efs, 'regular', utils.pathJoin(n1, n3));
475+
await efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4));
476+
await efs.unlink(utils.pathJoin(n2, n4));
478477
await efs.chmod(n1, 0o0644);
479478
await expectError(
480-
efs.link(path.join(n1, n3), path.join(n1, n4)),
479+
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n1, n4)),
481480
ErrorEncryptedFSError,
482481
errno.EACCES,
483482
);
484483
await expectError(
485-
efs.link(path.join(n1, n3), path.join(n2, n4)),
484+
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4)),
486485
ErrorEncryptedFSError,
487486
errno.EACCES,
488487
);
489488
await efs.chmod(n1, 0o0755);
490489
await efs.chmod(n2, 0o0644);
491490
await expectError(
492-
efs.link(path.join(n1, n3), path.join(n2, n4)),
491+
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4)),
493492
ErrorEncryptedFSError,
494493
errno.EACCES,
495494
);
@@ -500,20 +499,20 @@ describe(`${EncryptedFS.name} Links`, () => {
500499
await efs.mkdir(n2, { mode: dp });
501500
await efs.chown(n2, tuid, tuid);
502501
setId(efs, tuid);
503-
await createFile(efs, 'regular', path.join(n1, n3));
502+
await createFile(efs, 'regular', utils.pathJoin(n1, n3));
504503

505-
await efs.link(path.join(n1, n3), path.join(n2, n4));
506-
await efs.unlink(path.join(n2, n4));
504+
await efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4));
505+
await efs.unlink(utils.pathJoin(n2, n4));
507506

508507
await efs.chmod(n2, 0o0555);
509508
await expectError(
510-
efs.link(path.join(n1, n3), path.join(n2, n4)),
509+
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4)),
511510
ErrorEncryptedFSError,
512511
errno.EACCES,
513512
);
514513
await efs.chmod(n1, 0o0555);
515514
await expectError(
516-
efs.link(path.join(n1, n3), path.join(n1, n4)),
515+
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n1, n4)),
517516
ErrorEncryptedFSError,
518517
errno.EACCES,
519518
);
@@ -522,23 +521,23 @@ describe(`${EncryptedFS.name} Links`, () => {
522521
await efs.symlink(n0, n1);
523522
await efs.symlink(n1, n0);
524523
await expectError(
525-
efs.link(path.join(n0, 'test'), n2),
524+
efs.link(utils.pathJoin(n0, 'test'), n2),
526525
ErrorEncryptedFSError,
527526
errno.ELOOP,
528527
);
529528
await expectError(
530-
efs.link(path.join(n1, 'test'), n2),
529+
efs.link(utils.pathJoin(n1, 'test'), n2),
531530
ErrorEncryptedFSError,
532531
errno.ELOOP,
533532
);
534533
await createFile(efs, 'regular', n2);
535534
await expectError(
536-
efs.link(n2, path.join(n0, 'test')),
535+
efs.link(n2, utils.pathJoin(n0, 'test')),
537536
ErrorEncryptedFSError,
538537
errno.ELOOP,
539538
);
540539
await expectError(
541-
efs.link(n2, path.join(n1, 'test')),
540+
efs.link(n2, utils.pathJoin(n1, 'test')),
542541
ErrorEncryptedFSError,
543542
errno.ELOOP,
544543
);

tests/EncryptedFS.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os from 'os';
2-
import path from 'path';
32
import fs from 'fs';
43
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
54
import EncryptedFS from '@/EncryptedFS';
@@ -14,7 +13,7 @@ describe(EncryptedFS.name, () => {
1413
let dataDir: string;
1514
beforeEach(async () => {
1615
dataDir = await fs.promises.mkdtemp(
17-
path.join(os.tmpdir(), 'encryptedfs-test-'),
16+
utils.pathJoin(os.tmpdir(), 'encryptedfs-test-'),
1817
);
1918
});
2019
afterEach(async () => {
@@ -119,13 +118,13 @@ describe(EncryptedFS.name, () => {
119118
});
120119
test('iNode allocation across restarts', async () => {
121120
const d1 = 'dir1';
122-
const d1f1 = path.join(d1, 'file1');
123-
const d1f2 = path.join(d1, 'file2');
124-
const d1f3 = path.join(d1, 'file3');
121+
const d1f1 = utils.pathJoin(d1, 'file1');
122+
const d1f2 = utils.pathJoin(d1, 'file2');
123+
const d1f3 = utils.pathJoin(d1, 'file3');
125124
const d2 = 'dir2';
126-
const d2f1 = path.join(d2, 'file1');
127-
const d2f2 = path.join(d2, 'file2');
128-
const d2f3 = path.join(d2, 'file3');
125+
const d2f1 = utils.pathJoin(d2, 'file1');
126+
const d2f2 = utils.pathJoin(d2, 'file2');
127+
const d2f3 = utils.pathJoin(d2, 'file3');
129128

130129
let efs = await EncryptedFS.createEncryptedFS({
131130
dbPath: dataDir,
@@ -178,5 +177,6 @@ describe(EncryptedFS.name, () => {
178177
expect(await listNodes(efs)).toEqual([1, 3, 4, 5, 6, 7, 8, 9, 10]);
179178
// Note that 2 is skipped, this seems to be incremented
180179
// but not created when the RFS is created
180+
await efs.stop();
181181
});
182182
});

tests/fd/FileDescriptor.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os from 'os';
2-
import path from 'path';
32
import fs from 'fs';
43
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
54
import { DB } from '@matrixai/db';
@@ -22,7 +21,7 @@ describe('File Descriptor', () => {
2221
const origBuffer = Buffer.from('Test Buffer for File Descriptor');
2322
beforeEach(async () => {
2423
dataDir = await fs.promises.mkdtemp(
25-
path.join(os.tmpdir(), 'encryptedfs-test-'),
24+
utils.pathJoin(os.tmpdir(), 'encryptedfs-test-'),
2625
);
2726
db = await DB.createDB({
2827
dbPath: `${dataDir}/db`,

0 commit comments

Comments
 (0)