0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-06-10 03:43:16 +02:00

TestGetFileSize -> TestGetFileSizeParsesHumanSizes, refactor to cover more cases

This commit is contained in:
DmitryFrolovTri 2026-01-27 19:24:05 +00:00
parent a779d6412d
commit 86d591803a
No known key found for this signature in database
GPG Key ID: 0FBA4D49377CDDC3

View File

@ -91,11 +91,25 @@ func TestFileSize(t *testing.T) {
assert.Equal(t, "2.0 EiB", FileSize(size))
}
func TestGetFileSize(t *testing.T) {
var size int64 = 512 * 1024 * 1024 * 1024
s, err := GetFileSize("512 GiB")
assert.Equal(t, s, size)
assert.NoError(t, err)
func TestGetFileSizeParsesHumanSizes(t *testing.T) {
cases := []struct {
in string
want int64
}{
{"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) {