Refactor server to go-sqlite and ginext [WIP]

This commit is contained in:
2024-07-16 17:19:55 +02:00
parent 55d0dea835
commit c204dc5a8b
38 changed files with 2547 additions and 1983 deletions

View File

@@ -124,3 +124,26 @@ func TestRequestLogSimple(t *testing.T) {
}
}
func TestRequestLogAPI(t *testing.T) {
ws, baseUrl, stop := tt.StartSimpleWebserver(t)
defer stop()
data := tt.InitDefaultData(t, ws)
time.Sleep(100 * time.Millisecond)
ctx := ws.NewSimpleTransactionContext(5 * time.Second)
defer ctx.Cancel()
rl1, _, err := ws.Database.Requests.ListRequestLogs(ctx, models.RequestLogFilter{}, nil, ct.Start())
tt.TestFailIfErr(t, err)
time.Sleep(100 * time.Millisecond)
tt.RequestAuthGet[gin.H](t, data.User[0].ReadKey, baseUrl, "/api/v2/users/"+data.User[0].UID)
rl2, _, err := ws.Database.Requests.ListRequestLogs(ctx, models.RequestLogFilter{}, nil, ct.Start())
tt.TestFailIfErr(t, err)
time.Sleep(100 * time.Millisecond)
tt.AssertEqual(t, "requestlog.count", len(rl1)+1, len(rl2))
}

View File

@@ -12,7 +12,6 @@ func SetBufLogger() {
buflogger = &BufferWriter{cw: createConsoleWriter()}
log.Logger = createLogger(buflogger)
gin.SetMode(gin.ReleaseMode)
ginext.SuppressGinLogs = true
}
func ClearBufLogger(dump bool) {
@@ -23,7 +22,6 @@ func ClearBufLogger(dump bool) {
log.Logger = createLogger(createConsoleWriter())
buflogger = nil
gin.SetMode(gin.TestMode)
ginext.SuppressGinLogs = false
if !dump {
log.Info().Msgf("Suppressed %d logmessages / printf-statements", size)
}

View File

@@ -7,6 +7,7 @@ import (
"blackforestbytes.com/simplecloudnotifier/jobs"
"blackforestbytes.com/simplecloudnotifier/logic"
"blackforestbytes.com/simplecloudnotifier/push"
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"os"
"path/filepath"
@@ -87,7 +88,13 @@ func StartSimpleWebserver(t *testing.T) (*logic.Application, string, func()) {
TestFailErr(t, err)
}
ginengine := ginext.NewEngine(scn.Conf)
ginengine := ginext.NewEngine(ginext.Options{
AllowCors: &scn.Conf.Cors,
GinDebug: &scn.Conf.GinDebug,
BufferBody: langext.PTrue,
Timeout: langext.Ptr(time.Duration(int64(scn.Conf.RequestTimeout) * int64(scn.Conf.RequestMaxRetry))),
BuildRequestBindError: logic.BuildGinRequestError,
})
router := api.NewRouter(app)