refactor: drop two unmaintained dependencies, rename the byte size helpers (#39083)

This commit is contained in:
silverwind
2026-08-27 17:31:20 +02:00
committed by GitHub
parent 3b6ce586a7
commit 66c672d0b7
33 changed files with 197 additions and 180 deletions
-7
View File
@@ -16,8 +16,6 @@ import (
"gitea.dev/modules/setting"
"gitea.dev/modules/util"
"github.com/dustin/go-humanize"
)
// EncodeSha256 string to sha256 hex value.
@@ -92,11 +90,6 @@ func CreateTimeLimitCode[T time.Time | string](data string, minutes int, startTi
return code
}
// FileSize calculates the file size and generate user-friendly string.
func FileSize(s int64) string {
return humanize.IBytes(uint64(s))
}
// StringsToInt64s converts a slice of string to a slice of int64.
func StringsToInt64s(strs []string) ([]int64, error) {
if strs == nil {
-17
View File
@@ -76,23 +76,6 @@ JWT_SECRET = %s
})
}
func TestFileSize(t *testing.T) {
var size int64 = 512
assert.Equal(t, "512 B", FileSize(size))
size *= 1024
assert.Equal(t, "512 KiB", FileSize(size))
size *= 1024
assert.Equal(t, "512 MiB", FileSize(size))
size *= 1024
assert.Equal(t, "512 GiB", FileSize(size))
size *= 1024
assert.Equal(t, "512 TiB", FileSize(size))
size *= 1024
assert.Equal(t, "512 PiB", FileSize(size))
size *= 4
assert.Equal(t, "2.0 EiB", FileSize(size))
}
func TestStringsToInt64s(t *testing.T) {
testSuccess := func(input []string, expected []int64) {
result, err := StringsToInt64s(input)