From 0a06cd98a8c13264054a17fd6929a955de16a238 Mon Sep 17 00:00:00 2001 From: Robert Gogolok Date: Mon, 28 Oct 2024 18:07:34 +0100 Subject: [PATCH] Support floating point number values for disk_quota and memory Fixes #3546 --- api/payloads/manifest.go | 2 +- api/payloads/manifest_test.go | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/api/payloads/manifest.go b/api/payloads/manifest.go index a8d39ecbd..61c241cba 100644 --- a/api/payloads/manifest.go +++ b/api/payloads/manifest.go @@ -256,7 +256,7 @@ func (s ManifestApplicationService) Validate() error { return validation.ValidateStruct(&s, validation.Field(&s.Name, validation.Required)) } -var unitAmount = regexp.MustCompile(`^\d+(?:B|K|KB|M|m|MB|mb|G|g|GB|gb|T|t|TB|tb)$`) +var unitAmount = regexp.MustCompile(`^\d+(?:\.\d+)?(?:B|K|KB|M|m|MB|mb|G|g|GB|gb|T|t|TB|tb)$`) func validateAmountWithUnit(value any) error { v, isNil := validation.Indirect(value) diff --git a/api/payloads/manifest_test.go b/api/payloads/manifest_test.go index 96602ede5..028d21b93 100644 --- a/api/payloads/manifest_test.go +++ b/api/payloads/manifest_test.go @@ -123,6 +123,16 @@ var _ = Describe("Manifest payload", func() { }) }) + When("the disk quota is a floating point number", func() { + BeforeEach(func() { + testManifest.DiskQuota = tools.PtrTo("1.5G") + }) + + It("does not return a validation error", func() { + Expect(validateErr).NotTo(HaveOccurred()) + }) + }) + When("the alt disk quota doesn't supply a unit", func() { BeforeEach(func() { testManifest.AltDiskQuota = tools.PtrTo("1024") @@ -204,6 +214,16 @@ var _ = Describe("Manifest payload", func() { }) }) + When("the memory is a floating point number", func() { + BeforeEach(func() { + testManifest.Memory = tools.PtrTo("0.5G") + }) + + It("does not return a validation error", func() { + Expect(validateErr).NotTo(HaveOccurred()) + }) + }) + When("random-route and default-route flags are both set", func() { BeforeEach(func() { testManifest.DefaultRoute = true @@ -436,6 +456,16 @@ var _ = Describe("Manifest payload", func() { }) }) + When("the disk quota is a floating point number", func() { + BeforeEach(func() { + testManifestProcess.DiskQuota = tools.PtrTo("1.5G") + }) + + It("does not return a validation error", func() { + Expect(validateErr).NotTo(HaveOccurred()) + }) + }) + When("the alt disk quota doesn't supply a unit", func() { BeforeEach(func() { testManifestProcess.AltDiskQuota = tools.PtrTo("1024") @@ -517,6 +547,16 @@ var _ = Describe("Manifest payload", func() { }) }) + When("the memory is a floating point number", func() { + BeforeEach(func() { + testManifestProcess.Memory = tools.PtrTo("0.5G") + }) + + It("does not return a validation error", func() { + Expect(validateErr).NotTo(HaveOccurred()) + }) + }) + When("Timeout is not positive", func() { BeforeEach(func() { testManifestProcess.Timeout = tools.PtrTo(int32(0))