diff --git a/formatter_test.go b/formatter_test.go deleted file mode 100644 index f5496ed..0000000 --- a/formatter_test.go +++ /dev/null @@ -1,106 +0,0 @@ -package slogformatter - -import ( - "context" - "log/slog" - "sync/atomic" - "testing" - "time" - - slogmock "github.com/samber/slog-mock" - "github.com/stretchr/testify/assert" -) - -func TestFormatByKind(t *testing.T) { - t.Parallel() - is := assert.New(t) - - handler := NewFormatterMiddleware( - FormatByKind(slog.KindDuration, func(v slog.Value) slog.Value { - return slog.StringValue(v.Duration().String()) - }), - ) - - var checked int32 - - logger := slog.New( - handler( - slogmock.Option{ - Handle: func(ctx context.Context, record slog.Record) error { - is.Equal("hello world", record.Message) - - attrs := map[string]slog.Value{} - record.Attrs(func(attr slog.Attr) bool { - attrs[attr.Key] = attr.Value - return true - }) - - is.Len(attrs, 2) - is.Equal(attrs["key"], slog.StringValue("value")) - is.Equal(attrs["subgroup"].Kind(), slog.KindGroup) - is.Equal(attrs["subgroup"].Group()[0].Key, "duration") - is.Equal(attrs["subgroup"].Group()[0].Value, slog.StringValue("1s")) - - atomic.AddInt32(&checked, 1) - return nil - }, - }.NewMockHandler(), - ), - ) - - logger.Info("hello world", - slog.String("key", "value"), - slog.Group("subgroup", - slog.Duration("duration", 1*time.Second), - ), - ) - - is.Equal(int32(1), atomic.LoadInt32(&checked)) -} - -func TestFormatByKey(t *testing.T) { - t.Parallel() - is := assert.New(t) - - handler := NewFormatterMiddleware( - FormatByKey("duration", func(v slog.Value) slog.Value { - return slog.StringValue(v.Duration().String()) - }), - ) - - var checked int32 - - logger := slog.New( - handler( - slogmock.Option{ - Handle: func(ctx context.Context, record slog.Record) error { - is.Equal("hello world", record.Message) - - attrs := map[string]slog.Value{} - record.Attrs(func(attr slog.Attr) bool { - attrs[attr.Key] = attr.Value - return true - }) - - is.Len(attrs, 2) - is.Equal(attrs["key"], slog.StringValue("value")) - is.Equal(attrs["subgroup"].Kind(), slog.KindGroup) - is.Equal(attrs["subgroup"].Group()[0].Key, "duration") - is.Equal(attrs["subgroup"].Group()[0].Value, slog.StringValue("1s")) - - atomic.AddInt32(&checked, 1) - return nil - }, - }.NewMockHandler(), - ), - ) - - logger.Info("hello world", - slog.String("key", "value"), - slog.Group("subgroup", - slog.Duration("duration", 1*time.Second), - ), - ) - - is.Equal(int32(1), atomic.LoadInt32(&checked)) -} diff --git a/go.mod b/go.mod index becd74f..e422493 100644 --- a/go.mod +++ b/go.mod @@ -4,17 +4,6 @@ go 1.21 require github.com/samber/slog-multi v1.3.3 -require ( - github.com/samber/lo v1.47.0 - github.com/samber/slog-mock v0.1.0 - github.com/stretchr/testify v1.10.0 - go.uber.org/goleak v1.3.0 -) +require github.com/samber/lo v1.47.0 -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/kr/text v0.2.0 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/text v0.18.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) +require golang.org/x/text v0.18.0 // indirect diff --git a/go.sum b/go.sum index 6df69ff..19050f4 100644 --- a/go.sum +++ b/go.sum @@ -1,26 +1,6 @@ -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= -github.com/samber/slog-mock v0.1.0 h1:I3PApMma8+qoxrfh/MoTmHAWTN8CZyrOKAn1FXus7zU= -github.com/samber/slog-mock v0.1.0/go.mod h1:muKl65H9go1idsAoiDnetK/8pIQY/1X760/UwGD+REI= github.com/samber/slog-multi v1.3.3 h1:qhFXaYdW73FIWLt8SrXMXfPwY58NpluzKDwRdPvhWWY= github.com/samber/slog-multi v1.3.3/go.mod h1:ACuZ5B6heK57TfMVkVknN2UZHoFfjCwRxR0Q2OXKHlo= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main_test.go b/main_test.go deleted file mode 100644 index 381acc8..0000000 --- a/main_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package slogformatter - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -}