Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Do not allow floats as memory value #480

Merged
merged 1 commit into from
May 24, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Object {
"isRequired": Object {
"flavor": false,
},
"validation": null,
"value": undefined,
},
"name": Object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { get } from 'lodash';

import { isFieldRequired } from '../utils/vmSettingsTabUtils';
import { getValidationObject, validateContainer, validateVmName, validateURL } from '../../../../utils/validations';
import {
getValidationObject,
validateContainer,
validateVmName,
validateURL,
validateMemory,
} from '../../../../utils/validations';
import { objectMerge } from '../../../../utils/utils';
import { settingsValue } from '../../../../k8s/selectors';
import { PROVISION_SOURCE_IMPORT, VALIDATION_ERROR_TYPE } from '../../../../constants';
Expand All @@ -13,6 +19,7 @@ import {
PROVIDER_KEY,
PROVIDERS_DATA_KEY,
PROVISION_SOURCE_TYPE_KEY,
MEMORY_KEY,
} from '../constants';
import { NAMESPACE_MUST_BE_SELECTED } from '../../../../utils/strings';
import { isProviderValid, validateProvider } from '../providers';
Expand Down Expand Up @@ -40,6 +47,7 @@ const validateResolver = {
[CONTAINER_IMAGE_KEY]: asVmSettingsValidator(validateContainer),
[IMAGE_URL_KEY]: asVmSettingsValidator(validateURL),
[PROVIDER_KEY]: validateProviderDropdown,
[MEMORY_KEY]: asVmSettingsValidator(validateMemory),
};

export const validateVmSettings = (vmSettings, additionalResources) => {
Expand Down
9 changes: 8 additions & 1 deletion src/utils/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { VALIDATION_ERROR_TYPE } from '../constants';
import { getName, getNamespace } from '../selectors';
import { NAMESPACE_KEY, VIRTUAL_MACHINES_KEY } from '../components/Wizard/CreateVmWizard/constants';

export const isPositiveNumber = value => value && value.match(/^[1-9]\d*$/);
export const isPositiveNumber = value => value && value.toString().match(/^[1-9]\d*$/);

const alphanumberincRegex = '[a-zA-Z0-9]';

Expand Down Expand Up @@ -69,6 +69,13 @@ export const validateVmName = (value, vmSettings, props) => {
: vmAlreadyExists(value, get(vmSettings, `${NAMESPACE_KEY}.value`), props[VIRTUAL_MACHINES_KEY]);
};

export const validateMemory = value => {
if (!value) {
return getValidationObject(EMPTY_ERROR);
}
return isPositiveNumber(value) ? null : getValidationObject('must be positive integer');
};

export const validateURL = value => {
if (!value) {
return getValidationObject(EMPTY_ERROR);
Expand Down