From 6582c01aba97ddb1885eff4075963f15e99a2bd3 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Tue, 23 Sep 2025 12:52:42 +0000 Subject: [PATCH] treewide: satisfy go vet checks Signed-off-by: oppiliappan --- appview/db/label.go | 2 +- appview/pages/funcmap.go | 30 +++++++++++++++--------------- appview/pages/funcmap_test.go | 30 ++++++++++++++++++++++++++++++ appview/pages/pages.go | 4 ---- appview/reporesolver/resolver.go | 2 +- appview/state/state.go | 2 +- 6 file(s) changed, 48 insertion(s)(+), 22 deletion(s)(-) diff --git a/appview/db/label.go b/appview/db/label.go --- a/appview/db/label.go +++ b/appview/db/label.go @@ -349,5 +349,5 @@ for _, l := range labels { defs[l.AtUri().String()] = &l } - return &models.LabelApplicationCtx{defs}, nil + return &models.LabelApplicationCtx{Defs: defs}, nil } diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -141,21 +141,21 @@ "commaFmt": humanize.Comma, "relTimeFmt": humanize.Time, "shortRelTimeFmt": func(t time.Time) string { return humanize.CustomRelTime(t, time.Now(), "", "", []humanize.RelTimeMagnitude{ - {time.Second, "now", time.Second}, - {2 * time.Second, "1s %s", 1}, - {time.Minute, "%ds %s", time.Second}, - {2 * time.Minute, "1min %s", 1}, - {time.Hour, "%dmin %s", time.Minute}, - {2 * time.Hour, "1hr %s", 1}, - {humanize.Day, "%dhrs %s", time.Hour}, - {2 * humanize.Day, "1d %s", 1}, - {20 * humanize.Day, "%dd %s", humanize.Day}, - {8 * humanize.Week, "%dw %s", humanize.Week}, - {humanize.Year, "%dmo %s", humanize.Month}, - {18 * humanize.Month, "1y %s", 1}, - {2 * humanize.Year, "2y %s", 1}, - {humanize.LongTime, "%dy %s", humanize.Year}, - {math.MaxInt64, "a long while %s", 1}, + {D: time.Second, Format: "now", DivBy: time.Second}, + {D: 2 * time.Second, Format: "1s %s", DivBy: 1}, + {D: time.Minute, Format: "%ds %s", DivBy: time.Second}, + {D: 2 * time.Minute, Format: "1min %s", DivBy: 1}, + {D: time.Hour, Format: "%dmin %s", DivBy: time.Minute}, + {D: 2 * time.Hour, Format: "1hr %s", DivBy: 1}, + {D: humanize.Day, Format: "%dhrs %s", DivBy: time.Hour}, + {D: 2 * humanize.Day, Format: "1d %s", DivBy: 1}, + {D: 20 * humanize.Day, Format: "%dd %s", DivBy: humanize.Day}, + {D: 8 * humanize.Week, Format: "%dw %s", DivBy: humanize.Week}, + {D: humanize.Year, Format: "%dmo %s", DivBy: humanize.Month}, + {D: 18 * humanize.Month, Format: "1y %s", DivBy: 1}, + {D: 2 * humanize.Year, Format: "2y %s", DivBy: 1}, + {D: humanize.LongTime, Format: "%dy %s", DivBy: humanize.Year}, + {D: math.MaxInt64, Format: "a long while %s", DivBy: 1}, }) }, "longTimeFmt": func(t time.Time) string { diff --git a/appview/pages/funcmap_test.go b/appview/pages/funcmap_test.go new file mode 100644 --- /dev/null +++ b/appview/pages/funcmap_test.go @@ -0,0 +1,30 @@ +package pages + +import ( + "html/template" + "tangled.org/core/appview/config" + "tangled.org/core/idresolver" + "testing" +) + +func TestPages_funcMap(t *testing.T) { + tests := []struct { + name string // description of this test case + // Named input parameters for receiver constructor. + config *config.Config + res *idresolver.Resolver + want template.FuncMap + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := NewPages(tt.config, tt.res) + got := p.funcMap() + // TODO: update the condition below to compare got with tt.want. + if true { + t.Errorf("funcMap() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/appview/pages/pages.go b/appview/pages/pages.go --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -83,10 +83,6 @@ return p } -func (p *Pages) pathToName(s string) string { - return strings.TrimSuffix(strings.TrimPrefix(s, "templates/"), ".html") -} - // reverse of pathToName func (p *Pages) nameToPath(s string) string { return "templates/" + s + ".html" diff --git a/appview/reporesolver/resolver.go b/appview/reporesolver/resolver.go --- a/appview/reporesolver/resolver.go +++ b/appview/reporesolver/resolver.go @@ -212,7 +212,7 @@ func (f *ResolvedRepo) RolesInRepo(u *oauth.User) repoinfo.RolesInRepo { if u != nil { r := f.rr.enforcer.GetPermissionsInRepo(u.Did, f.Knot, f.DidSlashRepo()) - return repoinfo.RolesInRepo{r} + return repoinfo.RolesInRepo{Roles: r} } else { return repoinfo.RolesInRepo{} } diff --git a/appview/state/state.go b/appview/state/state.go --- a/appview/state/state.go +++ b/appview/state/state.go @@ -87,7 +87,7 @@ } repoResolver := reporesolver.New(config, enforcer, res, d) - wrapper := db.DbWrapper{d} + wrapper := db.DbWrapper{Execer: d} jc, err := jetstream.NewJetstreamClient( config.Jetstream.Endpoint, "appview", -- tangled.sh