tss-rocks/backend/pkg/logger/logger_test.go
CDN 05ddc1f783
Some checks failed
Build Backend / Build Docker Image (push) Successful in 3m33s
Test Backend / test (push) Failing after 31s
[feature] migrate to monorepo
2025-02-21 00:49:20 +08:00

85 lines
1.6 KiB
Go

package logger
import (
"testing"
"tss-rocks-be/internal/config"
"github.com/rs/zerolog"
)
func TestSetup(t *testing.T) {
tests := []struct {
name string
config *config.Config
expectedLevel zerolog.Level
}{
{
name: "Debug level",
config: &config.Config{
Logging: struct {
Level string `yaml:"level"`
Format string `yaml:"format"`
}{
Level: "debug",
Format: "json",
},
},
expectedLevel: zerolog.DebugLevel,
},
{
name: "Info level",
config: &config.Config{
Logging: struct {
Level string `yaml:"level"`
Format string `yaml:"format"`
}{
Level: "info",
Format: "json",
},
},
expectedLevel: zerolog.InfoLevel,
},
{
name: "Error level",
config: &config.Config{
Logging: struct {
Level string `yaml:"level"`
Format string `yaml:"format"`
}{
Level: "error",
Format: "json",
},
},
expectedLevel: zerolog.ErrorLevel,
},
{
name: "Invalid level defaults to Info",
config: &config.Config{
Logging: struct {
Level string `yaml:"level"`
Format string `yaml:"format"`
}{
Level: "invalid",
Format: "json",
},
},
expectedLevel: zerolog.InfoLevel,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Setup(tt.config)
if zerolog.GlobalLevel() != tt.expectedLevel {
t.Errorf("Setup() set level to %v, want %v", zerolog.GlobalLevel(), tt.expectedLevel)
}
})
}
}
func TestGetLogger(t *testing.T) {
logger := GetLogger()
if logger == nil {
t.Error("GetLogger() returned nil")
}
}