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