mirror of
https://github.com/affaan-m/ECC.git
synced 2026-10-29 11:55:19 +00:00
test: make directory identity mocks safe for Windows inodes
This commit is contained in:
1 parent
563e70ab92
commit
37f2bbf6c9
1 file changed
+15
-1
@@ -34,10 +34,24 @@ function mockEnumeration(context, entriesFor) {
|
||||
|
||||
function changedIdentity(stats) {
|
||||
const changed = Object.assign(Object.create(Object.getPrototypeOf(stats)), stats);
|
||||
changed.ino = typeof stats.ino === 'bigint' ? stats.ino + 1n : stats.ino + 1;
|
||||
// Windows inode numbers can exceed safe integer precision, so adding 1 may be a no-op.
|
||||
const zero = typeof stats.ino === 'bigint' ? 0n : 0;
|
||||
const one = typeof stats.ino === 'bigint' ? 1n : 1;
|
||||
changed.ino = stats.ino === zero ? one : zero;
|
||||
return changed;
|
||||
}
|
||||
|
||||
test('identity mock changes inode values beyond safe integer precision', () => {
|
||||
for (const ino of [0, 1, 2 ** 60, 0n, 1n, 2n ** 60n]) {
|
||||
const stats = { ino, dev: 1, mode: 16877 };
|
||||
const changed = changedIdentity(stats);
|
||||
assert.notEqual(changed.ino, stats.ino);
|
||||
assert.equal(typeof changed.ino, typeof stats.ino);
|
||||
assert.equal(changed.dev, stats.dev);
|
||||
assert.equal(changed.mode, stats.mode);
|
||||
}
|
||||
});
|
||||
|
||||
function samePath(left, right) {
|
||||
const normalize = value => path.resolve(value).toLowerCase();
|
||||
return normalize(left) === normalize(right);
|
||||
|
||||
Reference in new issue
Block a user