mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-06 10:17:37 +02:00
TestGetFileSize -> TestGetFileSizeParsesHumanSizes, refactor to cover more cases
This commit is contained in:
1 file changed
+19
-5
@@ -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) {
|
||||||
|
|||||||
Reference in new issue
Block a user