Skip to content

Commit 0526888

Browse files
committed
vfs: split followup tests into named test files
Replace the monolithic test-vfs-followups.js with individual test files: - test-vfs-overlapping-mounts.js - test-vfs-promises-open.js - test-vfs-stream-properties.js - test-vfs-dir-disposal.js - test-vfs-stats-ino-dev.js - test-vfs-append-write.js - test-vfs-cross-device.js - test-vfs-readdir-symlink-recursive.js - test-vfs-package-json-cache.js - test-vfs-readfile-async.js
1 parent 7346ef3 commit 0526888

11 files changed

Lines changed: 266 additions & 257 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
// writeSync in append mode must append, not overwrite.
4+
5+
require('../common');
6+
const assert = require('assert');
7+
const vfs = require('node:vfs');
8+
9+
const myVfs = vfs.create();
10+
myVfs.writeFileSync('/append.txt', 'init');
11+
12+
const fd = myVfs.openSync('/append.txt', 'a');
13+
const buf = Buffer.from(' more');
14+
myVfs.writeSync(fd, buf, 0, buf.length);
15+
myVfs.closeSync(fd);
16+
17+
const content = myVfs.readFileSync('/append.txt', 'utf8');
18+
assert.strictEqual(content, 'init more');
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
// Cross-VFS rename, copyFile, and link must throw EXDEV.
4+
5+
require('../common');
6+
const assert = require('assert');
7+
const fs = require('fs');
8+
const vfs = require('node:vfs');
9+
10+
const vfs1 = vfs.create();
11+
vfs1.writeFileSync('/src.txt', 'data');
12+
vfs1.mount('/xdev_a');
13+
14+
const vfs2 = vfs.create();
15+
vfs2.mkdirSync('/dest');
16+
vfs2.mount('/xdev_b');
17+
18+
assert.throws(() => fs.renameSync('/xdev_a/src.txt', '/xdev_b/dest/src.txt'), {
19+
code: 'EXDEV',
20+
});
21+
22+
assert.throws(() => fs.copyFileSync('/xdev_a/src.txt', '/xdev_b/dest/src.txt'), {
23+
code: 'EXDEV',
24+
});
25+
26+
assert.throws(() => fs.linkSync('/xdev_a/src.txt', '/xdev_b/dest/link.txt'), {
27+
code: 'EXDEV',
28+
});
29+
30+
vfs2.unmount();
31+
vfs1.unmount();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
// VirtualDir must support Symbol.dispose and Symbol.asyncDispose.
4+
5+
const common = require('../common');
6+
const assert = require('assert');
7+
const fs = require('fs');
8+
const vfs = require('node:vfs');
9+
10+
const myVfs = vfs.create();
11+
myVfs.mkdirSync('/dir');
12+
myVfs.writeFileSync('/dir/a.txt', 'a');
13+
myVfs.mount('/mnt_dirdispose');
14+
15+
// Symbol.dispose via closeSync
16+
{
17+
const dir = fs.opendirSync('/mnt_dirdispose/dir');
18+
dir[Symbol.dispose]();
19+
assert.throws(() => dir.closeSync(), { code: 'ERR_DIR_CLOSED' });
20+
}
21+
22+
// Symbol.asyncDispose via close
23+
{
24+
const dir = fs.opendirSync('/mnt_dirdispose/dir');
25+
dir[Symbol.asyncDispose]().then(common.mustCall(() => {
26+
assert.throws(() => dir.closeSync(), { code: 'ERR_DIR_CLOSED' });
27+
}));
28+
}
29+
30+
myVfs.unmount();

test/parallel/test-vfs-followups.js

Lines changed: 0 additions & 257 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
// Overlapping VFS mounts must be rejected.
4+
5+
require('../common');
6+
const assert = require('assert');
7+
const vfs = require('node:vfs');
8+
9+
const vfs1 = vfs.create();
10+
vfs1.writeFileSync('/a.txt', 'a');
11+
vfs1.mount('/overlap_base');
12+
13+
// Child of existing mount
14+
{
15+
const v = vfs.create();
16+
v.writeFileSync('/b.txt', 'b');
17+
assert.throws(() => v.mount('/overlap_base/sub'), {
18+
code: 'ERR_INVALID_STATE',
19+
message: /overlaps/,
20+
});
21+
}
22+
23+
// Parent of existing mount
24+
{
25+
const v = vfs.create();
26+
v.writeFileSync('/b.txt', 'b');
27+
assert.throws(() => v.mount('/overlap'), {
28+
code: 'ERR_INVALID_STATE',
29+
message: /overlaps/,
30+
});
31+
}
32+
33+
// Exact same mount point
34+
{
35+
const v = vfs.create();
36+
v.writeFileSync('/b.txt', 'b');
37+
assert.throws(() => v.mount('/overlap_base'), {
38+
code: 'ERR_INVALID_STATE',
39+
message: /overlaps/,
40+
});
41+
}
42+
43+
vfs1.unmount();

0 commit comments

Comments
 (0)