Skip to content

Commit

Permalink
Hide input value from kbn-config-schema error messages (elastic#58843)
Browse files Browse the repository at this point in the history
* use inline snapshots instead of snapshots

* hide input value from error messages

* update core snapshots

* update xpack snapshots

* fix ftr assertions

* fix new snapshots

* hide values for byte_size and duration

* update new snapshots

* remove another byte_size value reference

* fix yet another value references in error messages

* update xpack snapshots

* update xpack ftr assertions
  • Loading branch information
pgayvallet committed Mar 6, 2020
1 parent 56a7c58 commit e383219
Show file tree
Hide file tree
Showing 66 changed files with 532 additions and 609 deletions.

This file was deleted.

20 changes: 15 additions & 5 deletions packages/kbn-config-schema/src/byte_size_value/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,29 @@ describe('parsing units', () => {
});

test('throws an error when unsupported unit specified', () => {
expect(() => ByteSizeValue.parse('1tb')).toThrowErrorMatchingSnapshot();
expect(() => ByteSizeValue.parse('1tb')).toThrowErrorMatchingInlineSnapshot(
`"Failed to parse value as byte value. Value must be either number of bytes, or follow the format <count>[b|kb|mb|gb] (e.g., '1024kb', '200mb', '1gb'), where the number is a safe positive integer."`
);
});
});

describe('#constructor', () => {
test('throws if number of bytes is negative', () => {
expect(() => new ByteSizeValue(-1024)).toThrowErrorMatchingSnapshot();
expect(() => new ByteSizeValue(-1024)).toThrowErrorMatchingInlineSnapshot(
`"Value in bytes is expected to be a safe positive integer."`
);
});

test('throws if number of bytes is not safe', () => {
expect(() => new ByteSizeValue(NaN)).toThrowErrorMatchingSnapshot();
expect(() => new ByteSizeValue(Infinity)).toThrowErrorMatchingSnapshot();
expect(() => new ByteSizeValue(Math.pow(2, 53))).toThrowErrorMatchingSnapshot();
expect(() => new ByteSizeValue(NaN)).toThrowErrorMatchingInlineSnapshot(
`"Value in bytes is expected to be a safe positive integer."`
);
expect(() => new ByteSizeValue(Infinity)).toThrowErrorMatchingInlineSnapshot(
`"Value in bytes is expected to be a safe positive integer."`
);
expect(() => new ByteSizeValue(Math.pow(2, 53))).toThrowErrorMatchingInlineSnapshot(
`"Value in bytes is expected to be a safe positive integer."`
);
});

test('accepts 0', () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/kbn-config-schema/src/byte_size_value/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ByteSizeValue {
const number = Number(text);
if (typeof number !== 'number' || isNaN(number)) {
throw new Error(
`Failed to parse [${text}] as byte value. Value must be either number of bytes, or follow the format <count>[b|kb|mb|gb] ` +
`Failed to parse value as byte value. Value must be either number of bytes, or follow the format <count>[b|kb|mb|gb] ` +
`(e.g., '1024kb', '200mb', '1gb'), where the number is a safe positive integer.`
);
}
Expand All @@ -53,9 +53,7 @@ export class ByteSizeValue {

constructor(private readonly valueInBytes: number) {
if (!Number.isSafeInteger(valueInBytes) || valueInBytes < 0) {
throw new Error(
`Value in bytes is expected to be a safe positive integer, but provided [${valueInBytes}].`
);
throw new Error(`Value in bytes is expected to be a safe positive integer.`);
}
}

Expand Down
6 changes: 2 additions & 4 deletions packages/kbn-config-schema/src/duration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function stringToDuration(text: string) {
const number = Number(text);
if (typeof number !== 'number' || isNaN(number)) {
throw new Error(
`Failed to parse [${text}] as time value. Value must be a duration in milliseconds, or follow the format ` +
`Failed to parse value as time value. Value must be a duration in milliseconds, or follow the format ` +
`<count>[ms|s|m|h|d|w|M|Y] (e.g. '70ms', '5s', '3d', '1Y'), where the duration is a safe positive integer.`
);
}
Expand All @@ -43,9 +43,7 @@ function stringToDuration(text: string) {

function numberToDuration(numberMs: number) {
if (!Number.isSafeInteger(numberMs) || numberMs < 0) {
throw new Error(
`Value in milliseconds is expected to be a safe positive integer, but provided [${numberMs}].`
);
throw new Error(`Value in milliseconds is expected to be a safe positive integer.`);
}

return momentDuration(numberMs);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit e383219

Please sign in to comment.