-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlayout_utils_test.go
67 lines (53 loc) · 1.6 KB
/
layout_utils_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
56
57
58
59
60
61
62
63
64
65
66
67
package log4g
import (
. "gopkg.in/check.v1"
"time"
)
type layoutUtilsSuite struct {
}
var _ = Suite(&layoutUtilsSuite{})
func (s *layoutUtilsSuite) TestParseLayoutFail(c *C) {
t, err := ParseLayout("%A")
c.Assert(t, IsNil)
c.Assert(err, NotNil)
t, err = ParseLayout("%d(123)")
c.Assert(t, IsNil)
c.Assert(err, NotNil)
t, err = ParseLayout("%dd{1234}")
c.Assert(t, IsNil)
c.Assert(err, NotNil)
t, err = ParseLayout("%d(123)")
c.Assert(t, IsNil)
c.Assert(err, NotNil)
t, err = ParseLayout("%d{123")
c.Assert(t, IsNil)
c.Assert(err, NotNil)
t, err = ParseLayout("%")
c.Assert(t, IsNil)
c.Assert(err, NotNil)
}
func (s *layoutUtilsSuite) TestParseLayout(c *C) {
t, _ := ParseLayout(" ")
c.Assert(len(t), Equals, 1)
c.Assert(t[0].value, Equals, " ")
c.Assert(t[0].pieceType, Equals, lpText)
t, _ = ParseLayout("Text")
c.Assert(len(t), Equals, 1)
c.Assert(t[0].value, Equals, "Text")
c.Assert(t[0].pieceType, Equals, lpText)
t, _ = ParseLayout("%c%p%d{123}%m%%")
c.Assert(len(t), Equals, 5)
c.Assert(t[0].pieceType, Equals, lpLoggerName)
c.Assert(t[1].pieceType, Equals, lpLogLevel)
c.Assert(t[2].value, Equals, "123")
c.Assert(t[2].pieceType, Equals, lpDate)
c.Assert(t[3].pieceType, Equals, lpMessage)
c.Assert(t[4].pieceType, Equals, lpText)
t, _ = ParseLayout("%c %p %d{123} %m %% %% ")
c.Assert(len(t), Equals, 10)
}
func (s *layoutUtilsSuite) TestToLogMessage(c *C) {
t, _ := ParseLayout("[%d{01-02 15:04:05.000}] %p %c: %%%m")
le := &LogEvent{FATAL, time.Unix(123456, 0), "a.b.c", "The Message"}
c.Assert(ToLogMessage(le, t), Equals, "[01-02 02:17:36.000] FATAL a.b.c: %The Message")
}