85 lines
1.6 KiB
Go
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")
|
|
}
|
|
}
|