Skip to content

Commit 43417a5

Browse files
authored
deploymentsize: Fixes a bug in ParseGb() (#183)
Fixes a bug where defining memory size in capital letters failed with a misleading error.
1 parent 7ae1b54 commit 43417a5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pkg/api/deploymentapi/deploymentsize/sizes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ const minsize = 512
2929
// ParseGb converts the stringified gigabyte size notation to an int32 Megabyte
3030
// notation. The minimum size allowed is 0.5g Megabytes with 0.5g increments.
3131
func ParseGb(strSize string) (int32, error) {
32+
strSize = strings.ToLower(strSize)
3233
re := regexp.MustCompile(`(?m)(.*\w)(g)`)
33-
matches := re.FindStringSubmatch(strings.ToLower(strSize))
34+
matches := re.FindStringSubmatch(strSize)
3435
if len(matches) < 2 {
3536
fmt.Println(matches, "length", len(matches))
3637
return 0, fmt.Errorf(`failed to convert "%s" to <size><g>`, strSize)

pkg/api/deploymentapi/deploymentsize/sizes_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ func TestParse(t *testing.T) {
4242
name: "parses a 8gb (gigabyte notation)",
4343
args: args{strSize: "8gb"}, want: 8 * 1024,
4444
},
45+
{
46+
name: "parses a 0.5G (gigabyte notation)",
47+
args: args{strSize: "0.5G"}, want: 512,
48+
},
49+
{
50+
name: "parses a 8GB (gigabyte notation)",
51+
args: args{strSize: "8GB"}, want: 8 * 1024,
52+
},
4553
{
4654
name: "trying to parse 512m returns a failure",
4755
args: args{strSize: "512m"},

0 commit comments

Comments
 (0)