diff options
author | 2022-07-12 08:32:20 +0100 | |
---|---|---|
committer | 2022-07-12 08:32:20 +0100 | |
commit | 6934ae378ab5743da80a5995fc74d167502187b1 (patch) | |
tree | 6e3f58498158f1e844504961338eadb18f5a590e /testrig/gin.go | |
parent | [performance] Add new index to fix slow web profile queries (#706) (diff) | |
download | gotosocial-6934ae378ab5743da80a5995fc74d167502187b1.tar.xz |
[chore] improved router logging, recovery and error handling (#705)
* move panic recovery to logging middleware, improve logging + panic recovery logic
Signed-off-by: kim <grufwub@gmail.com>
* remove dead code
Signed-off-by: kim <grufwub@gmail.com>
* remove skip paths code
Signed-off-by: kim <grufwub@gmail.com>
* re-enable log quoting
Signed-off-by: kim <grufwub@gmail.com>
* use human-friendly bytesize in logging body size
Signed-off-by: kim <grufwub@gmail.com>
* only disable quoting in debug builds
Signed-off-by: kim <grufwub@gmail.com>
* use logrus level instead of debug.DEBUG() to enable/disable quoting
Signed-off-by: kim <grufwub@gmail.com>
* shutup linter
Signed-off-by: kim <grufwub@gmail.com>
* fix instance tests
Signed-off-by: kim <grufwub@gmail.com>
* fix gin test contexts created with missing engine HTML renderer
Signed-off-by: kim <grufwub@gmail.com>
* add note regarding not logging query parameters
Signed-off-by: kim <grufwub@gmail.com>
* better explain 'DisableQuoting' logic
Signed-off-by: kim <grufwub@gmail.com>
* add license text
Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'testrig/gin.go')
-rw-r--r-- | testrig/gin.go | 37 |
1 files changed, 37 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. +*/ + +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 +} |