From 6934ae378ab5743da80a5995fc74d167502187b1 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Tue, 12 Jul 2022 08:32:20 +0100 Subject: [chore] improved router logging, recovery and error handling (#705) * move panic recovery to logging middleware, improve logging + panic recovery logic Signed-off-by: kim * remove dead code Signed-off-by: kim * remove skip paths code Signed-off-by: kim * re-enable log quoting Signed-off-by: kim * use human-friendly bytesize in logging body size Signed-off-by: kim * only disable quoting in debug builds Signed-off-by: kim * use logrus level instead of debug.DEBUG() to enable/disable quoting Signed-off-by: kim * shutup linter Signed-off-by: kim * fix instance tests Signed-off-by: kim * fix gin test contexts created with missing engine HTML renderer Signed-off-by: kim * add note regarding not logging query parameters Signed-off-by: kim * better explain 'DisableQuoting' logic Signed-off-by: kim * add license text Signed-off-by: kim --- testrig/gin.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 testrig/gin.go (limited to 'testrig/gin.go') diff --git a/testrig/gin.go b/testrig/gin.go new file mode 100644 index 000000000..853dfdd06 --- /dev/null +++ b/testrig/gin.go @@ -0,0 +1,37 @@ +/* + GoToSocial + Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package testrig + +import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/superseriousbusiness/gotosocial/internal/router" +) + +// CreateGinTextContext creates a new gin.Context suitable for a test, with an instantiated gin.Engine. +func CreateGinTestContext(rw http.ResponseWriter, r *http.Request) (*gin.Context, *gin.Engine) { + ctx, eng := gin.CreateTestContext(rw) + router.LoadTemplateFunctions(eng) + if err := router.LoadTemplates(eng); err != nil { + panic(err) + } + ctx.Request = r + return ctx, eng +} -- cgit v1.2.3