From be395968fe65fff4745d8a171d5373948ef7c069 Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 26 Apr 2021 08:59:43 +0200 Subject: [PATCH] use errHandler in admin tests --- web/handlers/admin/invites_test.go | 3 +-- web/handlers/admin/notices_test.go | 2 +- web/handlers/admin/setup_test.go | 10 +++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/web/handlers/admin/invites_test.go b/web/handlers/admin/invites_test.go index 95a43272..7b6161fa 100644 --- a/web/handlers/admin/invites_test.go +++ b/web/handlers/admin/invites_test.go @@ -159,8 +159,7 @@ func TestInvitesCreate(t *testing.T) { _, userID := ts.InvitesDB.CreateArgsForCall(totalCreateCallCount - 1) a.EqualValues(ts.User.ID, userID) } else { - // TODO: status should be http.StatusForbidden? see invites.go:79 - a.Equal(http.StatusInternalServerError, rec.Code) + a.Equal(http.StatusForbidden, rec.Code) r.Equal(totalCreateCallCount, ts.InvitesDB.CreateCallCount()) } return rec diff --git a/web/handlers/admin/notices_test.go b/web/handlers/admin/notices_test.go index 724fb8cb..1ca75a17 100644 --- a/web/handlers/admin/notices_test.go +++ b/web/handlers/admin/notices_test.go @@ -89,7 +89,7 @@ func TestNoticeAddLanguageOnlyAllowsPost(t *testing.T) { // verify that a GET request is no bueno u := ts.URLTo(router.AdminNoticeAddTranslation, "name", roomdb.NoticeNews.String()) _, resp := ts.Client.GetHTML(u) - a.Equal(http.StatusMethodNotAllowed, resp.Code, "GET should not be allowed for this route") + a.Equal(http.StatusBadRequest, resp.Code, "GET should not be allowed for this route") // next up, we verify that a correct POST request actually works: id := []string{"1"} diff --git a/web/handlers/admin/setup_test.go b/web/handlers/admin/setup_test.go index d37b2e8a..f3e2e97c 100644 --- a/web/handlers/admin/setup_test.go +++ b/web/handlers/admin/setup_test.go @@ -130,10 +130,10 @@ func newSession(t *testing.T) *testSession { os.MkdirAll(sessionsPath, 0700) fsStore := sessions.NewFilesystemStore(sessionsPath, authKey, encKey) - flashHelper := weberrs.NewFlashHelper(fsStore, locHelper) - // setup rendering + flashHelper := weberrs.NewFlashHelper(fsStore, locHelper) + // template funcs // TODO: make testing utils and move these there testFuncs := web.TemplateFuncs(router, ts.netInfo) testFuncs["current_page_is"] = func(routeName string) bool { return true } @@ -152,11 +152,13 @@ func newSession(t *testing.T) *testSession { testFuncs["list_languages"] = func(*url.URL, string) string { return "" } testFuncs["relative_time"] = func(when time.Time) string { return humanize.Time(when) } + eh := weberrs.NewErrorHandler(locHelper, flashHelper) + renderOpts := []render.Option{ render.SetLogger(log), render.BaseTemplates("base.tmpl", "menu.tmpl", "flashes.tmpl"), render.AddTemplates(append(HTMLTemplates, "error.tmpl")...), - render.ErrorTemplate("error.tmpl"), + render.SetErrorHandler(eh.Handle), render.FuncMap(testFuncs), } renderOpts = append(renderOpts, locHelper.GetRenderFuncs()...) @@ -166,6 +168,8 @@ func newSession(t *testing.T) *testSession { t.Fatal(errors.Wrap(err, "setup: render init failed")) } + eh.SetRenderer(r) + handler := Handler( ts.netInfo, r,