From 86f37ea6b5976904e885f3e36c9fe9131019de60 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Tue, 23 Sep 2025 13:52:42 +0100 Subject: [PATCH] treewide: satisfy go vet checks Change-Id: qkpqqspxtxtqnvvoskrnzrqvxmpppmxy 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 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 appview/pages/funcmap_test.go diff --git a/appview/db/label.go b/appview/db/label.go index 7ab92465..e323ebb9 100644 --- a/appview/db/label.go +++ b/appview/db/label.go @@ -349,5 +349,5 @@ func NewLabelApplicationCtx(e Execer, filters ...filter) (*models.LabelApplicati 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 index b78beb2d..0ad47269 100644 --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -141,21 +141,21 @@ func (p *Pages) funcMap() template.FuncMap { "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 index 00000000..2b92aaaa --- /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 index 5f5ccf77..df37834b 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -83,10 +83,6 @@ func NewPages(config *config.Config, res *idresolver.Resolver) *Pages { 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 index 24575486..c2f73f84 100644 --- a/appview/reporesolver/resolver.go +++ b/appview/reporesolver/resolver.go @@ -212,7 +212,7 @@ func (f *ResolvedRepo) RepoInfo(user *oauth.User) repoinfo.RepoInfo { 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 index 197c735e..364e1a2e 100644 --- a/appview/state/state.go +++ b/appview/state/state.go @@ -87,7 +87,7 @@ func Make(ctx context.Context, config *config.Config) (*State, error) { repoResolver := reporesolver.New(config, enforcer, res, d) - wrapper := db.DbWrapper{d} + wrapper := db.DbWrapper{Execer: d} jc, err := jetstream.NewJetstreamClient( config.Jetstream.Endpoint, "appview", -- 2.43.0