This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user