From d6fedcb57e116ebbf62dc5c74080f4e984d2b307 Mon Sep 17 00:00:00 2001 From: Dave Poole Date: Fri, 9 Feb 2024 20:27:26 +0000 Subject: [PATCH] feedback --- main/schema.go | 9 ++++++--- main/schema_test.go | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/main/schema.go b/main/schema.go index c28ff20..d7bbe76 100644 --- a/main/schema.go +++ b/main/schema.go @@ -62,12 +62,15 @@ const ( "memoryLimitInBytes": { "description": "Optional - specifies the max memory that vmwatch can use", "type": "integer", - "default": 80000000 + "default": 80000000, + "minimum": 30000000 }, - "macCpuPercentage": { + "maxCpuPercentage": { "description": "Optional - specifies the max cpu that the vmwatch process is allowed to consume", "type": "integer", - "default": 1 + "default": 1, + "minimum": 1, + "maximum": 100 }, "signalFilters" : { "description": "Optional - specify filtering for signals, if not specified, all core signals will be enabled", diff --git a/main/schema_test.go b/main/schema_test.go index 9b1bb2c..5acf9d7 100644 --- a/main/schema_test.go +++ b/main/schema_test.go @@ -154,3 +154,22 @@ func TestValidatePublicSettings_gracePeriod(t *testing.T) { }) } } + +func TestValidatePublicSettings_vmwatch(t *testing.T) { + require.Nil(t, validatePublicSettings(`{"port": 1, "vmWatchSettings" : { "enabled" : false }}`), "valid settings") + require.Nil(t, validatePublicSettings(`{"port": 1, "vmWatchSettings" : { "enabled" : true }}`), "valid settings") + require.Nil(t, validatePublicSettings(`{"port": 1, "vmWatchSettings" : { "enabled" : true, "memoryLimitInBytes" : 30000000 }}`), "valid settings") + + err := validatePublicSettings(`{"port": 1, "vmWatchSettings" : { "enabled" : true, "memoryLimitInBytes" : 20000000 }}`) + require.NotNil(t, err) + require.Contains(t, err.Error(), "vmWatchSettings.memoryLimitInBytes: Must be greater than or equal to 30000000") + + err = validatePublicSettings(`{"port": 1, "vmWatchSettings" : { "enabled" : true, "maxCpuPercentage" : 0 }}`) + require.NotNil(t, err) + require.Contains(t, err.Error(), "vmWatchSettings.maxCpuPercentage: Must be greater than or equal to 1") + + err = validatePublicSettings(`{"port": 1, "vmWatchSettings" : { "enabled" : true, "maxCpuPercentage" : 101 }}`) + require.NotNil(t, err) + require.Contains(t, err.Error(), "vmWatchSettings.maxCpuPercentage: Must be less than or equal to 100") +} +