Skip to content
Merged
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
6 changes: 5 additions & 1 deletion frontend/public/components/__tests__/units.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ describe('units', () => {
test_(1073741824, '1 GiB');
test_(1099511627776, '1 TiB');
test_(1125899906842624, '1 PiB');
test_(1152921504606846976, '1 EiB');
});

describe('should humanize binaryBytesWithoutB values', () => {
Expand Down Expand Up @@ -219,6 +220,7 @@ describe('units', () => {
test_(1073741824, '1 Gi');
test_(1099511627776, '1 Ti');
test_(1125899906842624, '1 Pi');
test_(1152921504606846976, '1 Ei');
});

describe('should de-humanize binaryBytesWithoutB values', () => {
Expand Down Expand Up @@ -257,6 +259,7 @@ describe('units', () => {
test_('1Gi', 1073741824);
test_('1Ti', 1099511627776);
test_('1Pi', 1125899906842624);
test_('1Ei', 1152921504606846976);
test_('100 i', 100);
test_('100 Ki', 102400);
});
Expand All @@ -283,7 +286,7 @@ describe('units', () => {

describe('validate', () => {
it('memory', () => {
['32', '32M', '32Mi'].forEach((v) => {
['32', '32M', '32Mi', '1Ei'].forEach((v) => {
expect(validate.memory(v)).toEqual(undefined);
});

Expand Down Expand Up @@ -357,6 +360,7 @@ describe('convert to base value', () => {
test_('1Gi', 1073741824);
test_('1Ti', 1099511627776);
test_('1Pi', 1125899906842624);
test_('1Ei', 1152921504606846976);

// decimal memory units
test_('1k', 1000);
Expand Down
7 changes: 4 additions & 3 deletions frontend/public/components/utils/units.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const TYPES = {
divisor: 1000,
},
binaryBytes: {
units: ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'],
units: ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'],
space: true,
divisor: 1024,
},
Expand Down Expand Up @@ -103,7 +103,8 @@ const convertValueWithUnitsToBaseValue = (value, unitArray, divisor) => {
}
return false;
});
if (startingUnitIndex <= 0) {

if (startingUnitIndex < 0) {
// can't parse
return defaultReturn;
}
Expand Down Expand Up @@ -302,7 +303,7 @@ validate.CPU = (value = '') => {
return validateNumber(number) || validateCPUUnit(unit);
};

const validMemUnits = new Set(['E', 'P', 'T', 'G', 'M', 'k', 'Pi', 'Ti', 'Gi', 'Mi', 'Ki']);
const validMemUnits = new Set(['E', 'P', 'T', 'G', 'M', 'k', 'Ei', 'Pi', 'Ti', 'Gi', 'Mi', 'Ki']);
const validateMemUnit = (value = '') => {
if (validMemUnits.has(value)) {
return;
Expand Down