From f26b6b00d39a345d2bebd537626e0ff69c8368eb Mon Sep 17 00:00:00 2001 From: Francisco Carriedo Date: Mon, 21 Jul 2014 23:49:52 -0700 Subject: [PATCH] pkg/units: Standardized supported sizes May make sense that both `FromHumanSize()` and `RAMInBytes()` support the same units. Added 'PB' to the RAMInBytes regex. Also updated tests. Note: int64 is overflowed on quantities >= EB Docker-DCO-1.1-Signed-off-by: Francisco Carriedo (github: fcarriedo) --- units/size.go | 4 +++- units/size_test.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/units/size.go b/units/size.go index d8410b4..4a953fb 100644 --- a/units/size.go +++ b/units/size.go @@ -63,7 +63,7 @@ func FromHumanSize(size string) (int64, error) { // returns the number of bytes, or -1 if the string is unparseable. // Units are case-insensitive, and the 'b' suffix is optional. func RAMInBytes(size string) (int64, error) { - re, err := regexp.Compile("^(\\d+)([kKmMgGtT])?[bB]?$") + re, err := regexp.Compile("^(\\d+)([kKmMgGtTpP])?[bB]?$") if err != nil { return -1, err } @@ -90,6 +90,8 @@ func RAMInBytes(size string) (int64, error) { memLimit *= 1024 * 1024 * 1024 case "t": memLimit *= 1024 * 1024 * 1024 * 1024 + case "p": + memLimit *= 1024 * 1024 * 1024 * 1024 * 1024 } return memLimit, nil diff --git a/units/size_test.go b/units/size_test.go index de8b44f..a2dfedc 100644 --- a/units/size_test.go +++ b/units/size_test.go @@ -64,7 +64,11 @@ func TestRAMInBytes(t *testing.T) { assertRAMInBytes(t, "32MB", false, 32*1024*1024) assertRAMInBytes(t, "32Gb", false, 32*1024*1024*1024) assertRAMInBytes(t, "32G", false, 32*1024*1024*1024) + assertRAMInBytes(t, "32GB", false, 32*1024*1024*1024) assertRAMInBytes(t, "32Tb", false, 32*1024*1024*1024*1024) + assertRAMInBytes(t, "8Pb", false, 8*1024*1024*1024*1024*1024) + assertRAMInBytes(t, "8PB", false, 8*1024*1024*1024*1024*1024) + assertRAMInBytes(t, "8P", false, 8*1024*1024*1024*1024*1024) assertRAMInBytes(t, "", true, -1) assertRAMInBytes(t, "hello", true, -1)