Skip to content

Commit 2d55706

Browse files
committed
Add tests for no tag parsing
1 parent faa5e59 commit 2d55706

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

rfc3164/rfc3164_test.go

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package rfc3164
22

33
import (
44
"bytes"
5-
"github.com/Xiol/syslogparser"
6-
. "gopkg.in/check.v1"
75
"testing"
86
"time"
7+
8+
"github.com/Xiol/syslogparser"
9+
. "gopkg.in/check.v1"
910
)
1011

1112
// Hooks up gocheck into the gotest runner.
@@ -27,9 +28,10 @@ func (s *Rfc3164TestSuite) TestParser_Valid(c *C) {
2728

2829
p := NewParser(buff)
2930
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,
3335
}
3436

3537
c.Assert(p, DeepEquals, expectedP)
@@ -53,6 +55,38 @@ func (s *Rfc3164TestSuite) TestParser_Valid(c *C) {
5355
c.Assert(obtained, DeepEquals, expected)
5456
}
5557

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+
5690
func (s *Rfc3164TestSuite) TestParseHeader_Valid(c *C) {
5791
buff := []byte("Oct 11 22:14:15 mymachine ")
5892
now := time.Now()
@@ -143,6 +177,13 @@ func (s *Rfc3164TestSuite) TestParseTag_TrailingSpace(c *C) {
143177
s.assertTag(c, tag, buff, len(buff), nil)
144178
}
145179

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+
146187
func (s *Rfc3164TestSuite) TestParseContent_Valid(c *C) {
147188
buff := []byte(" foo bar baz quux ")
148189
content := string(bytes.Trim(buff, " "))

0 commit comments

Comments
 (0)