From 80f8977e596db4fbeac43c37af3c123c4c4b95f6 Mon Sep 17 00:00:00 2001 From: truecode112 Date: Tue, 16 May 2023 12:27:49 +0300 Subject: [PATCH] fixed issues for testing --- modules/base/tool.go | 5 ++++- modules/base/tool_test.go | 7 +++++++ routers/web/admin/repos.go | 13 ++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/modules/base/tool.go b/modules/base/tool.go index 96d1391e3a8..5fe486b9b96 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -138,7 +138,10 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string // FileSize calculates the file size and generate user-friendly string. func FileSize(s int64) string { - return humanize.Bytes(uint64(s)) + // sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB"} + // return humanize.humanateBytes(uint64(s), 1000, sizes) + // return humanize.Bytes(uint64(s)) + return humanize.IBytes(uint64(s)) } // Get FileSize bytes value from String. diff --git a/modules/base/tool_test.go b/modules/base/tool_test.go index 0c3e76704ea..8834d0e9727 100644 --- a/modules/base/tool_test.go +++ b/modules/base/tool_test.go @@ -114,6 +114,13 @@ 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.Equal(t, err, nil) +} + func TestEllipsisString(t *testing.T) { assert.Equal(t, "...", EllipsisString("foobar", 0)) assert.Equal(t, "...", EllipsisString("foobar", 1)) diff --git a/routers/web/admin/repos.go b/routers/web/admin/repos.go index f02ae8521ac..360d3166040 100644 --- a/routers/web/admin/repos.go +++ b/routers/web/admin/repos.go @@ -45,7 +45,18 @@ func Repos(ctx *context.Context) { } func UpdateRepoPost(ctx *context.Context) { - form := web.GetForm(ctx).(*forms.UpdateGlobalRepoFrom) + temp := web.GetForm(ctx) + if temp == nil { + ctx.Data["Err_Repo_Size_Limit"] = "" + explore.RenderRepoSearch(ctx, &explore.RepoSearchOptions{ + Private: true, + PageSize: setting.UI.Admin.RepoPagingNum, + TplName: tplRepos, + OnlyShowRelevant: false, + }) + return + } + form := temp.(*forms.UpdateGlobalRepoFrom) ctx.Data["Title"] = ctx.Tr("admin.repositories") ctx.Data["PageIsAdminRepositories"] = true