github.com/shogo82148/goa-v1@v1.6.2/logging/slog/adapter_test.go (about) 1 //go:build go1.21 2 // +build go1.21 3 4 package goaslog_test 5 6 import ( 7 "bytes" 8 "log/slog" 9 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 "github.com/shogo82148/goa-v1" 13 goaslog "github.com/shogo82148/goa-v1/logging/slog" 14 ) 15 16 var _ = Describe("goaslog", func() { 17 var handler slog.Handler 18 var adapter goa.LogAdapter 19 var buf bytes.Buffer 20 21 BeforeEach(func() { 22 handler = slog.NewJSONHandler(&buf, nil) 23 adapter = goaslog.New(handler) 24 }) 25 26 It("adapts info messages", func() { 27 msg := "msg" 28 adapter.Info(msg) 29 Ω(buf.String()).Should(ContainSubstring(msg)) 30 }) 31 32 It("adapts warn messages", func() { 33 adapter := adapter.(goa.WarningLogAdapter) 34 msg := "msg" 35 adapter.Warn(msg) 36 Ω(buf.String()).Should(ContainSubstring(msg)) 37 }) 38 39 It("adapts error messages", func() { 40 msg := "msg" 41 adapter.Error(msg) 42 Ω(buf.String()).Should(ContainSubstring(msg)) 43 }) 44 })