SimpleCloudNotifier/scnserver/test/util/init.go
Mike Schwörer b3ce926309
Some checks failed
Build Docker and Deploy / Build Docker Container (push) Successful in 1m19s
Build Docker and Deploy / Run Unit-Tests (push) Failing after 2m36s
Build Docker and Deploy / Deploy to Server (push) Has been skipped
Fis test pipeline
2024-09-20 21:14:40 +02:00

46 lines
839 B
Go

package util
import (
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"io"
"os"
)
func InitTests() {
log.Logger = createLogger(createConsoleWriter())
gin.SetMode(gin.TestMode)
if llstr, ok := os.LookupEnv("SCN_TEST_LOGLEVEL"); ok {
ll, err := zerolog.ParseLevel(llstr)
if err != nil {
panic(err)
}
zerolog.SetGlobalLevel(ll)
} else {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
}
func createConsoleWriter() *zerolog.ConsoleWriter {
return &zerolog.ConsoleWriter{
Out: os.Stdout,
TimeFormat: "2006-01-02 15:04:05.000 Z07:00",
}
}
func createLogger(cw io.Writer) zerolog.Logger {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMs
multi := zerolog.MultiLevelWriter(cw)
logger := zerolog.New(multi).With().
Timestamp().
Caller().
Logger()
return logger
}