TestGetFileSize -> TestGetFileSizeParsesHumanSizes, refactor to cover more cases

This commit is contained in:
DmitryFrolovTri committed 2026-01-28 08:47:43 +00:00
1 parent a779d6412d
commit 86d591803a
1 file changed
+19 -5
+19 -5
View File
@@ -91,11 +91,25 @@ func TestFileSize(t *testing.T) {
assert.Equal(t, "2.0 EiB", FileSize(size)) assert.Equal(t, "2.0 EiB", FileSize(size))
} }
func TestGetFileSize(t *testing.T) { func TestGetFileSizeParsesHumanSizes(t *testing.T) {
var size int64 = 512 * 1024 * 1024 * 1024 cases := []struct {
s, err := GetFileSize("512 GiB") in string
assert.Equal(t, s, size) want int64
assert.NoError(t, err) }{
{"11", 11},
{"11 B", 11},
{"11 KiB", 11 * 1024},
{"11 MiB", 11 * 1024 * 1024},
{"11 GiB", 11 * 1024 * 1024 * 1024},
{"11 TiB", 11 * 1024 * 1024 * 1024 * 1024},
{"11 PiB", 11 * 1024 * 1024 * 1024 * 1024 * 1024},
{"2 EiB", 2 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024},
}
for _, tc := range cases {
got, err := GetFileSize(tc.in)
assert.NoError(t, err, tc.in)
assert.Equal(t, tc.want, got, tc.in)
}
} }
func TestStringsToInt64s(t *testing.T) { func TestStringsToInt64s(t *testing.T) {