This commit is contained in:
toom1996
2026-09-29 19:59:30 +08:00
parent d15d2a4701
commit 361ffc01af
28 changed files with 896 additions and 47 deletions

View File

@ -0,0 +1,25 @@
package handler
import "testing"
// TestFormatBytes 校验后台「图集原图总大小」的字节格式化(0/负数为「—」)。
func TestFormatBytes(t *testing.T) {
cases := []struct {
n int64
want string
}{
{0, "—"},
{-1, "—"},
{500, "500 B"},
{1024, "1.0 KB"},
{1536, "1.5 KB"},
{1024 * 1024, "1.0 MB"},
{int64(1.5 * 1024 * 1024), "1.5 MB"},
{int64(1.5 * 1024 * 1024 * 1024), "1.5 GB"},
}
for _, c := range cases {
if got := formatBytes(c.n); got != c.want {
t.Errorf("formatBytes(%d) = %q, want %q", c.n, got, c.want)
}
}
}