Skip to content

Commit

Permalink
Support floating point number values for disk_quota and memory
Browse files Browse the repository at this point in the history
Fixes #3546
  • Loading branch information
gogolok authored and danail-branekov committed Oct 31, 2024
1 parent d0483c8 commit 0a06cd9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/payloads/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions api/payloads/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 0a06cd9

Please sign in to comment.