lib/config: Format bytes in insufficient space errors (fixes #5920) (#5921)

This commit is contained in:
Jakob Borg
2019-08-02 14:43:05 +02:00
committed by GitHub
parent 1475c0344a
commit 61b9f7bd55
2 changed files with 56 additions and 2 deletions

View File

@@ -91,3 +91,42 @@ func TestParseSize(t *testing.T) {
}
}
}
func TestFormatSI(t *testing.T) {
cases := []struct {
bytes int64
result string
}{
{
bytes: 0,
result: "0 ", // space for unit
},
{
bytes: 999,
result: "999 ",
},
{
bytes: 1000,
result: "1.0 K",
},
{
bytes: 1023 * 1000,
result: "1.0 M",
},
{
bytes: 5 * 1000 * 1000 * 1000,
result: "5.0 G",
},
{
bytes: 50000 * 1000 * 1000 * 1000 * 1000,
result: "50000.0 T",
},
}
for _, tc := range cases {
res := formatSI(tc.bytes)
if res != tc.result {
t.Errorf("formatSI(%d) => %q, expected %q", tc.bytes, res, tc.result)
}
}
}