Skip to content

Commit 9ba13ff

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 442a61f commit 9ba13ff

11 files changed

+212
-220
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-40
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe(`${EncryptedFS.name} Links`, () => {
7171
let stat2 = await efs.stat(n0);
7272
const time = stat2.birthtime.getTime();
7373
await sleep(100);
74-
await efs.symlink('test', path.join(n0, n1));
74+
await efs.symlink('test', utils.pathJoin(n0, n1));
7575
stat2 = await efs.stat(n0);
7676
const mtime = stat2.mtime.getTime();
7777
const ctime = stat2.ctime.getTime();
@@ -151,49 +151,49 @@ describe(`${EncryptedFS.name} Links`, () => {
151151
await efs.mkdir(n1, { mode: dp });
152152
await efs.chown(n1, tuid, tuid);
153153

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

157157
await efs.chmod(n1, 0o0644);
158158
setId(efs, tuid);
159159
await expectError(
160-
efs.symlink('test', path.join(n1, n2)),
160+
efs.symlink('test', utils.pathJoin(n1, n2)),
161161
ErrorEncryptedFSError,
162162
errno.EACCES,
163163
);
164164
await efs.chmod(n1, dp);
165-
await efs.symlink('test', path.join(n1, n2));
166-
await efs.unlink(path.join(n1, n2));
165+
await efs.symlink('test', utils.pathJoin(n1, n2));
166+
await efs.unlink(utils.pathJoin(n1, n2));
167167
});
168168
test('returns EACCES if the parent directory of the file to be created denies write permission', async () => {
169169
await efs.mkdir(n1, { mode: dp });
170170
await efs.chown(n1, tuid, tuid);
171171

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

176176
await efs.chmod(n1, 0o0555);
177177
setId(efs, tuid);
178178
await expectError(
179-
efs.symlink('test', path.join(n1, n2)),
179+
efs.symlink('test', utils.pathJoin(n1, n2)),
180180
ErrorEncryptedFSError,
181181
errno.EACCES,
182182
);
183183
await efs.chmod(n1, 0o0755);
184-
await efs.symlink('test', path.join(n1, n2));
185-
await efs.unlink(path.join(n1, n2));
184+
await efs.symlink('test', utils.pathJoin(n1, n2));
185+
await efs.unlink(utils.pathJoin(n1, n2));
186186
});
187187
test('returns ELOOP if too many symbolic links were encountered in translating the name2 path name', async () => {
188188
await efs.symlink(n0, n1);
189189
await efs.symlink(n1, n0);
190190
await expectError(
191-
efs.symlink('test', path.join(n0, 'test')),
191+
efs.symlink('test', utils.pathJoin(n0, 'test')),
192192
ErrorEncryptedFSError,
193193
errno.ELOOP,
194194
);
195195
await expectError(
196-
efs.symlink('test', path.join(n1, 'test')),
196+
efs.symlink('test', utils.pathJoin(n1, 'test')),
197197
ErrorEncryptedFSError,
198198
errno.ELOOP,
199199
);
@@ -254,9 +254,9 @@ describe(`${EncryptedFS.name} Links`, () => {
254254
});
255255
test('returns ENOTDIR if a component of the path prefix is not a directory', async () => {
256256
await efs.mkdir(n0, { mode: dp });
257-
await createFile(efs, 'regular', path.join(n0, n1));
257+
await createFile(efs, 'regular', utils.pathJoin(n0, n1));
258258
await expectError(
259-
efs.unlink(path.join(n0, n1, 'test')),
259+
efs.unlink(utils.pathJoin(n0, n1, 'test')),
260260
ErrorEncryptedFSError,
261261
errno.ENOTDIR,
262262
);
@@ -271,10 +271,10 @@ describe(`${EncryptedFS.name} Links`, () => {
271271
await efs.mkdir(n1, { mode: dp });
272272
await efs.chown(n1, tuid, tuid);
273273
setId(efs, tuid);
274-
await createFile(efs, 'regular', path.join(n1, n2));
274+
await createFile(efs, 'regular', utils.pathJoin(n1, n2));
275275
await efs.chmod(n1, 0o0644);
276276
await expectError(
277-
efs.unlink(path.join(n1, n2)),
277+
efs.unlink(utils.pathJoin(n1, n2)),
278278
ErrorEncryptedFSError,
279279
errno.EACCES,
280280
);
@@ -283,10 +283,10 @@ describe(`${EncryptedFS.name} Links`, () => {
283283
await efs.mkdir(n1, { mode: dp });
284284
await efs.chown(n1, tuid, tuid);
285285
setId(efs, tuid);
286-
await createFile(efs, 'regular', path.join(n1, n2));
286+
await createFile(efs, 'regular', utils.pathJoin(n1, n2));
287287
await efs.chmod(n1, 0o0555);
288288
await expectError(
289-
efs.unlink(path.join(n1, n2)),
289+
efs.unlink(utils.pathJoin(n1, n2)),
290290
ErrorEncryptedFSError,
291291
errno.EACCES,
292292
);
@@ -295,12 +295,12 @@ describe(`${EncryptedFS.name} Links`, () => {
295295
await efs.symlink(n0, n1);
296296
await efs.symlink(n1, n0);
297297
await expectError(
298-
efs.unlink(path.join(n0, 'test')),
298+
efs.unlink(utils.pathJoin(n0, 'test')),
299299
ErrorEncryptedFSError,
300300
errno.ELOOP,
301301
);
302302
await expectError(
303-
efs.unlink(path.join(n1, 'test')),
303+
efs.unlink(utils.pathJoin(n1, 'test')),
304304
ErrorEncryptedFSError,
305305
errno.ELOOP,
306306
);
@@ -451,15 +451,15 @@ describe(`${EncryptedFS.name} Links`, () => {
451451
async (type) => {
452452
if (type !== 'dir' && type !== 'symlink') {
453453
await efs.mkdir(n0, { mode: dp });
454-
await createFile(efs, type as FileTypes, path.join(n0, n1));
454+
await createFile(efs, type as FileTypes, utils.pathJoin(n0, n1));
455455
await expectError(
456-
efs.link(path.join(n0, n1, 'test'), path.join(n0, n2)),
456+
efs.link(utils.pathJoin(n0, n1, 'test'), utils.pathJoin(n0, n2)),
457457
ErrorEncryptedFSError,
458458
errno.ENOTDIR,
459459
);
460-
await createFile(efs, type as FileTypes, path.join(n0, n2));
460+
await createFile(efs, type as FileTypes, utils.pathJoin(n0, n2));
461461
await expectError(
462-
efs.link(path.join(n0, n2), path.join(n0, n1, 'test')),
462+
efs.link(utils.pathJoin(n0, n2), utils.pathJoin(n0, n1, 'test')),
463463
ErrorEncryptedFSError,
464464
errno.ENOTDIR,
465465
);
@@ -472,24 +472,24 @@ describe(`${EncryptedFS.name} Links`, () => {
472472
await efs.mkdir(n2, { mode: dp });
473473
await efs.chown(n2, tuid, tuid);
474474
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));
475+
await createFile(efs, 'regular', utils.pathJoin(n1, n3));
476+
await efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4));
477+
await efs.unlink(utils.pathJoin(n2, n4));
478478
await efs.chmod(n1, 0o0644);
479479
await expectError(
480-
efs.link(path.join(n1, n3), path.join(n1, n4)),
480+
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n1, n4)),
481481
ErrorEncryptedFSError,
482482
errno.EACCES,
483483
);
484484
await expectError(
485-
efs.link(path.join(n1, n3), path.join(n2, n4)),
485+
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4)),
486486
ErrorEncryptedFSError,
487487
errno.EACCES,
488488
);
489489
await efs.chmod(n1, 0o0755);
490490
await efs.chmod(n2, 0o0644);
491491
await expectError(
492-
efs.link(path.join(n1, n3), path.join(n2, n4)),
492+
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4)),
493493
ErrorEncryptedFSError,
494494
errno.EACCES,
495495
);
@@ -500,20 +500,20 @@ describe(`${EncryptedFS.name} Links`, () => {
500500
await efs.mkdir(n2, { mode: dp });
501501
await efs.chown(n2, tuid, tuid);
502502
setId(efs, tuid);
503-
await createFile(efs, 'regular', path.join(n1, n3));
503+
await createFile(efs, 'regular', utils.pathJoin(n1, n3));
504504

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

508508
await efs.chmod(n2, 0o0555);
509509
await expectError(
510-
efs.link(path.join(n1, n3), path.join(n2, n4)),
510+
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n2, n4)),
511511
ErrorEncryptedFSError,
512512
errno.EACCES,
513513
);
514514
await efs.chmod(n1, 0o0555);
515515
await expectError(
516-
efs.link(path.join(n1, n3), path.join(n1, n4)),
516+
efs.link(utils.pathJoin(n1, n3), utils.pathJoin(n1, n4)),
517517
ErrorEncryptedFSError,
518518
errno.EACCES,
519519
);
@@ -522,23 +522,23 @@ describe(`${EncryptedFS.name} Links`, () => {
522522
await efs.symlink(n0, n1);
523523
await efs.symlink(n1, n0);
524524
await expectError(
525-
efs.link(path.join(n0, 'test'), n2),
525+
efs.link(utils.pathJoin(n0, 'test'), n2),
526526
ErrorEncryptedFSError,
527527
errno.ELOOP,
528528
);
529529
await expectError(
530-
efs.link(path.join(n1, 'test'), n2),
530+
efs.link(utils.pathJoin(n1, 'test'), n2),
531531
ErrorEncryptedFSError,
532532
errno.ELOOP,
533533
);
534534
await createFile(efs, 'regular', n2);
535535
await expectError(
536-
efs.link(n2, path.join(n0, 'test')),
536+
efs.link(n2, utils.pathJoin(n0, 'test')),
537537
ErrorEncryptedFSError,
538538
errno.ELOOP,
539539
);
540540
await expectError(
541-
efs.link(n2, path.join(n1, 'test')),
541+
efs.link(n2, utils.pathJoin(n1, 'test')),
542542
ErrorEncryptedFSError,
543543
errno.ELOOP,
544544
);

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-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('File Descriptor', () => {
2222
const origBuffer = Buffer.from('Test Buffer for File Descriptor');
2323
beforeEach(async () => {
2424
dataDir = await fs.promises.mkdtemp(
25-
path.join(os.tmpdir(), 'encryptedfs-test-'),
25+
utils.pathJoin(os.tmpdir(), 'encryptedfs-test-'),
2626
);
2727
db = await DB.createDB({
2828
dbPath: `${dataDir}/db`,

tests/fd/FileDescriptorManager.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';
@@ -21,7 +20,7 @@ describe('File Descriptor Manager', () => {
2120
const origBuffer = Buffer.from('Test Buffer for File Descriptor');
2221
beforeEach(async () => {
2322
dataDir = await fs.promises.mkdtemp(
24-
path.join(os.tmpdir(), 'encryptedfs-test-'),
23+
utils.pathJoin(os.tmpdir(), 'encryptedfs-test-'),
2524
);
2625
db = await DB.createDB({
2726
dbPath: `${dataDir}/db`,

0 commit comments

Comments
 (0)