You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package logging
|
|
|
|
// Tests for logger construction and context-enriched loggers.
|
|
|
|
import (
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestNewLogger_NoPanic ensures new logger no panic behavior is handled correctly.
|
|
func TestNewLogger_NoPanic(t *testing.T) {
|
|
require.NotPanics(t, func() {
|
|
_ = NewLogger(Config{Level: "invalid", Environment: "development", Output: io.Discard})
|
|
})
|
|
|
|
require.NotPanics(t, func() {
|
|
_ = NewLogger(Config{Level: "info", Environment: "production", Output: nil})
|
|
})
|
|
}
|
|
|
|
// TestLogger_WithFields ensures logger with fields behavior is handled correctly.
|
|
func TestLogger_WithFields(t *testing.T) {
|
|
logger := NewLogger(DefaultConfig())
|
|
withField := logger.WithField("key", "value")
|
|
withFields := logger.WithFields(map[string]interface{}{"a": 1})
|
|
|
|
require.NotNil(t, withField)
|
|
require.NotNil(t, withFields)
|
|
require.NotNil(t, logger.Zerolog())
|
|
}
|
|
|
|
// TestDefaultConfig_Stable ensures default config stable behavior is handled correctly.
|
|
func TestDefaultConfig_Stable(t *testing.T) {
|
|
cfg := DefaultConfig()
|
|
require.Equal(t, "info", cfg.Level)
|
|
require.Equal(t, "development", cfg.Environment)
|
|
require.Equal(t, "knowfoolery", cfg.ServiceName)
|
|
require.Equal(t, "0.0.0", cfg.Version)
|
|
}
|