github.com/furusax0621/goa-v1@v1.4.3/logging/logrus/adapter_test.go (about) 1 package goalogrus_test 2 3 import ( 4 "bytes" 5 6 "context" 7 8 "github.com/goadesign/goa" 9 goalogrus "github.com/goadesign/goa/logging/logrus" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 "github.com/sirupsen/logrus" 13 ) 14 15 var _ = Describe("goalogrus", func() { 16 var logger *logrus.Logger 17 var adapter goa.LogAdapter 18 var buf bytes.Buffer 19 20 BeforeEach(func() { 21 logger = logrus.New() 22 logger.Out = &buf 23 adapter = goalogrus.New(logger) 24 }) 25 26 It("adapts info messages", func() { 27 msg := "msg" 28 adapter.Info(msg) 29 Ω(buf.String()).Should(ContainSubstring(msg)) 30 }) 31 }) 32 33 var _ = Describe("FromEntry", func() { 34 var entry *logrus.Entry 35 var adapter goa.LogAdapter 36 var buf bytes.Buffer 37 38 BeforeEach(func() { 39 logger := logrus.New() 40 logger.Out = &buf 41 entry = logrus.NewEntry(logger) 42 adapter = goalogrus.FromEntry(entry) 43 }) 44 45 It("creates an adapter that logs", func() { 46 msg := "msg" 47 adapter.Info(msg) 48 Ω(buf.String()).Should(ContainSubstring(msg)) 49 }) 50 51 Context("Entry", func() { 52 var ctx context.Context 53 54 BeforeEach(func() { 55 ctx = goa.WithLogger(context.Background(), adapter) 56 }) 57 58 It("extracts the log entry", func() { 59 Ω(goalogrus.Entry(ctx)).Should(Equal(entry)) 60 }) 61 }) 62 })