From 13232ad93da83837d0c09bc983c729eab4724d5c Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov <v.tolstov@unistack.org> Date: Fri, 27 Dec 2024 01:16:22 +0300 Subject: [PATCH] fixup Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org> --- logger/slog/slog_test.go | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/logger/slog/slog_test.go b/logger/slog/slog_test.go index 8f87b226..e8f4cd43 100644 --- a/logger/slog/slog_test.go +++ b/logger/slog/slog_test.go @@ -16,6 +16,25 @@ import ( "go.unistack.org/micro/v3/metadata" ) +// always first to have proper check +func TestStacktrace(t *testing.T) { + ctx := context.TODO() + buf := bytes.NewBuffer(nil) + l := NewLogger(logger.WithLevel(logger.ErrorLevel), logger.WithOutput(buf), + WithHandlerFunc(slog.NewTextHandler), + logger.WithAddStacktrace(true), + ) + if err := l.Init(logger.WithFields("key1", "val1")); err != nil { + t.Fatal(err) + } + + l.Error(ctx, "msg1", errors.New("err")) + + if !bytes.Contains(buf.Bytes(), []byte(`slog_test.go:31`)) { + t.Fatalf("logger error not works, buf contains: %s", buf.Bytes()) + } +} + func TestTime(t *testing.T) { ctx := context.TODO() buf := bytes.NewBuffer(nil) @@ -38,24 +57,6 @@ func TestTime(t *testing.T) { } } -func TestStacktrace(t *testing.T) { - ctx := context.TODO() - buf := bytes.NewBuffer(nil) - l := NewLogger(logger.WithLevel(logger.ErrorLevel), logger.WithOutput(buf), - WithHandlerFunc(slog.NewTextHandler), - logger.WithAddStacktrace(true), - ) - if err := l.Init(logger.WithFields("key1", "val1")); err != nil { - t.Fatal(err) - } - - l.Error(ctx, "msg1", errors.New("err")) - - if !bytes.Contains(buf.Bytes(), []byte(`slog_test.go:51`)) { - t.Fatalf("logger error not works, buf contains: %s", buf.Bytes()) - } -} - func TestWithFields(t *testing.T) { ctx := context.TODO() buf := bytes.NewBuffer(nil)