@@ -2,10 +2,11 @@ package rfc3164
2
2
3
3
import (
4
4
"bytes"
5
- "github.com/Xiol/syslogparser"
6
- . "gopkg.in/check.v1"
7
5
"testing"
8
6
"time"
7
+
8
+ "github.com/Xiol/syslogparser"
9
+ . "gopkg.in/check.v1"
9
10
)
10
11
11
12
// Hooks up gocheck into the gotest runner.
@@ -27,9 +28,10 @@ func (s *Rfc3164TestSuite) TestParser_Valid(c *C) {
27
28
28
29
p := NewParser (buff )
29
30
expectedP := & Parser {
30
- buff : buff ,
31
- cursor : 0 ,
32
- l : len (buff ),
31
+ buff : buff ,
32
+ cursor : 0 ,
33
+ l : len (buff ),
34
+ location : time .UTC ,
33
35
}
34
36
35
37
c .Assert (p , DeepEquals , expectedP )
@@ -53,6 +55,38 @@ func (s *Rfc3164TestSuite) TestParser_Valid(c *C) {
53
55
c .Assert (obtained , DeepEquals , expected )
54
56
}
55
57
58
+ func (s * Rfc3164TestSuite ) TestParser_ValidNoTag (c * C ) {
59
+ buff := []byte ("<34>Oct 11 22:14:15 mymachine singleword" )
60
+
61
+ p := NewParser (buff )
62
+ expectedP := & Parser {
63
+ buff : buff ,
64
+ cursor : 0 ,
65
+ l : len (buff ),
66
+ location : time .UTC ,
67
+ }
68
+
69
+ c .Assert (p , DeepEquals , expectedP )
70
+
71
+ err := p .Parse ()
72
+ c .Assert (err , IsNil )
73
+
74
+ now := time .Now ()
75
+
76
+ obtained := p .Dump ()
77
+ expected := syslogparser.LogParts {
78
+ "timestamp" : time .Date (now .Year (), time .October , 11 , 22 , 14 , 15 , 0 , time .UTC ),
79
+ "hostname" : "mymachine" ,
80
+ "tag" : "" ,
81
+ "content" : "singleword" ,
82
+ "priority" : 34 ,
83
+ "facility" : 4 ,
84
+ "severity" : 2 ,
85
+ }
86
+
87
+ c .Assert (obtained , DeepEquals , expected )
88
+ }
89
+
56
90
func (s * Rfc3164TestSuite ) TestParseHeader_Valid (c * C ) {
57
91
buff := []byte ("Oct 11 22:14:15 mymachine " )
58
92
now := time .Now ()
@@ -143,6 +177,13 @@ func (s *Rfc3164TestSuite) TestParseTag_TrailingSpace(c *C) {
143
177
s .assertTag (c , tag , buff , len (buff ), nil )
144
178
}
145
179
180
+ func (s * Rfc3164TestSuite ) TestParseTag_NoTag (c * C ) {
181
+ buff := []byte ("apache2" )
182
+ tag := ""
183
+
184
+ s .assertTag (c , tag , buff , 0 , nil )
185
+ }
186
+
146
187
func (s * Rfc3164TestSuite ) TestParseContent_Valid (c * C ) {
147
188
buff := []byte (" foo bar baz quux " )
148
189
content := string (bytes .Trim (buff , " " ))
0 commit comments