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.

33 lines
889 B
Go

package logging
// Tests for logger construction and context-enriched loggers.
import (
"io"
"testing"
"github.com/stretchr/testify/require"
)
// TestNewLogger_NoPanic verifies logger creation handles invalid levels and nil output.
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 verifies field-enriched loggers are created.
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())
}