Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve coverage of fs internal utils #38746

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions test/parallel/test-fs-util-validateoffsetlength.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');

const assert = require('assert');
const {
validateOffsetLengthRead,
validateOffsetLengthWrite,
} = require('internal/fs/utils');

{
const offset = -1;
assert.throws(
() => validateOffsetLengthRead(offset, 0, 0),
common.expectsError({
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be >= 0. Received ${offset}`
})
);
}

{
const length = -1;
assert.throws(
() => validateOffsetLengthRead(0, length, 0),
common.expectsError({
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "length" is out of range. ' +
`It must be >= 0. Received ${length}`
})
);
}

{
const offset = 1;
const length = 1;
const byteLength = offset + length - 1;
assert.throws(
() => validateOffsetLengthRead(offset, length, byteLength),
common.expectsError({
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "length" is out of range. ' +
`It must be <= ${byteLength - offset}. Received ${length}`
})
);
}

// Most platforms don't allow reads or writes >= 2 GB.
// See https://github.com/libuv/libuv/pull/1501.
const kIoMaxLength = 2 ** 31 - 1;

// RangeError when offset > byteLength
{
const offset = 100;
const length = 100;
const byteLength = 50;
assert.throws(
() => validateOffsetLengthWrite(offset, length, byteLength),
common.expectsError({
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "offset" is out of range. ' +
`It must be <= ${byteLength}. Received ${offset}`
})
);
}

// RangeError when byteLength < kIoMaxLength, and length > byteLength - offset.
{
const offset = kIoMaxLength - 150;
const length = 200;
const byteLength = kIoMaxLength - 100;
assert.throws(
() => validateOffsetLengthWrite(offset, length, byteLength),
common.expectsError({
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "length" is out of range. ' +
`It must be <= ${byteLength - offset}. Received ${length}`
})
);
}
43 changes: 0 additions & 43 deletions test/parallel/test-fs-util-validateoffsetlengthwrite.js

This file was deleted.