github.com/brycereitano/goa@v0.0.0-20170315073847-8ffa6c85e265/logging_test.go (about)

     1  package goa_test
     2  
     3  import (
     4  	"bytes"
     5  	"log"
     6  
     7  	"github.com/goadesign/goa"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	"golang.org/x/net/context"
    11  )
    12  
    13  var _ = Describe("Info", func() {
    14  	Context("with a nil Log", func() {
    15  		It("doesn't log and doesn't crash", func() {
    16  			Ω(func() { goa.LogInfo(context.Background(), "foo", "bar") }).ShouldNot(Panic())
    17  		})
    18  	})
    19  })
    20  
    21  var _ = Describe("Error", func() {
    22  	Context("with a nil Log", func() {
    23  		It("doesn't log and doesn't crash", func() {
    24  			Ω(func() { goa.LogError(context.Background(), "foo", "bar") }).ShouldNot(Panic())
    25  		})
    26  	})
    27  })
    28  
    29  var _ = Describe("LogAdapter", func() {
    30  	Context("with a valid Log", func() {
    31  		var logger goa.LogAdapter
    32  		const msg = "message"
    33  		data := []interface{}{"data", "foo"}
    34  
    35  		var out bytes.Buffer
    36  
    37  		BeforeEach(func() {
    38  			stdlogger := log.New(&out, "", log.LstdFlags)
    39  			logger = goa.NewLogger(stdlogger)
    40  		})
    41  
    42  		It("Info logs", func() {
    43  			logger.Info(msg, data...)
    44  			Ω(out.String()).Should(ContainSubstring(msg + " data=foo"))
    45  		})
    46  
    47  		It("Error logs", func() {
    48  			logger.Error(msg, data...)
    49  			Ω(out.String()).Should(ContainSubstring(msg + " data=foo"))
    50  		})
    51  	})
    52  })