From 2dabd202cee7a0f0e4ff2d0c1520a6c2a608c2dd Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 2 Apr 2024 13:34:17 +0200 Subject: [PATCH] [FEAT] Mark database errors in tests as failure - If the database returns a error in integration tests, it should be marked as a failure of the test. - Ref: https://codeberg.org/forgejo/forgejo/issues/2962 (this should help with logging the SQL that is resulting in the error). --- models/db/engine.go | 8 +++++++- modules/testlogger/testlogger.go | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/models/db/engine.go b/models/db/engine.go index 660ea1f5e3..27e5fb9e1a 100755 --- a/models/db/engine.go +++ b/models/db/engine.go @@ -155,8 +155,14 @@ func InitEngine(ctx context.Context) error { Logger: log.GetLogger("xorm"), }) } + + errorLogger := log.GetLogger("xorm") + if setting.IsInTesting { + errorLogger = log.GetLogger(log.DEFAULT) + } + xormEngine.AddHook(&ErrorQueryHook{ - Logger: log.GetLogger("xorm"), + Logger: errorLogger, }) SetDefaultEngine(ctx, xormEngine) diff --git a/modules/testlogger/testlogger.go b/modules/testlogger/testlogger.go index acabad09ad..7e8da8b131 100644 --- a/modules/testlogger/testlogger.go +++ b/modules/testlogger/testlogger.go @@ -393,6 +393,9 @@ var ignoredErrorMessage = []string{ // TestRenameInvalidUsername `TrString() [E] Missing translation "form.Name"`, + + // TestDatabaseCollation + `[E] [Error SQL Query] INSERT INTO test_collation_tbl (txt) VALUES ('main') []`, } func (w *testLoggerWriterCloser) recordError(msg string) {