-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
55 lines (46 loc) · 1.18 KB
/
message_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
53
54
55
package loggo
import (
"bytes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"text/template"
)
var _ = Describe("Message", func() {
name := "FOO"
content := "foo"
var msg *Message
var tpl *template.Template
getString := func(t *template.Template, msg *Message) string {
buffer := bytes.NewBufferString("")
t.Execute(buffer, msg)
return buffer.String()
}
BeforeEach(func() {
tpl, _ = template.New("foo").Parse(defaultFormat)
msg = &Message{
Name: name,
Level: Debug,
Content: content,
Time: dummyTime(),
dateFormat: defaultDateFormat,
tpl: tpl,
}
})
It("should format message", func() {
Expect(msg.String()).To(Equal(getString(tpl, msg)))
})
It("should respect template", func() {
msg.tpl, _ = template.New("foo").Parse("{{.Content}}")
Expect(msg.String()).To(Equal(content))
})
It("should use date format", func() {
f := "Jan 2, 2006 at 15:04pm (MST)"
msg.dateFormat = f
Expect(msg.String()).To(ContainSubstring(msg.Time.Format(f)))
})
It("should work with padding", func() {
msg.padding = true
msg.tpl, _ = template.New("foo").Parse("{{.LevelStr}}:")
Expect(msg.String()).To(Equal("DEBUG :"))
})
})