package units import "testing" func TestSizes(t *testing.T) { for in, want := range map[string]int64{"5G": 5120, "500M": 500, "1.5gb": 1536, "1T": 1048576, "20 GB": 20480} { if got, err := ParseSizeMB(in); err != nil || got != want { t.Fatalf("ParseSizeMB(%q) = %d, %v; want %d", in, got, err, want) } } if _, err := ParseSizeMB("+5G"); err == nil { t.Fatal("a signed size isn't a config size") } for mb, want := range map[int64]string{512: "512 MB", 5120: "5 GB", 2560: "2.5 GB", 1258291: "1.2 TB"} { if got := FormatMB(mb); got != want { t.Fatalf("FormatMB(%d) = %q, want %q", mb, got, want) } } }