Skip to content

Commit 96e0277

Browse files
committed
Add test suite for automatic formats
1 parent a16b0cf commit 96e0277

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

server_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,73 @@ func (s *ServerSuite) TestUDP6587(c *C) {
183183
c.Check(handler.LastMessageLength, Equals, int64(len(exampleRFC5424Syslog)))
184184
c.Check(handler.LastError, IsNil)
185185
}
186+
187+
func (s *ServerSuite) TestUDPAutomatic3164(c *C) {
188+
handler := new(HandlerMock)
189+
server := NewServer()
190+
server.SetFormat(Automatic)
191+
server.SetHandler(handler)
192+
server.SetTimeout(10)
193+
server.goParseDatagrams()
194+
server.datagramChannel <- DatagramMessage{[]byte(exampleSyslog), "0.0.0.0"}
195+
close(server.datagramChannel)
196+
server.Wait()
197+
c.Check(handler.LastLogParts["hostname"], Equals, "hostname")
198+
c.Check(handler.LastLogParts["tag"], Equals, "tag")
199+
c.Check(handler.LastLogParts["content"], Equals, "content")
200+
c.Check(handler.LastMessageLength, Equals, int64(len(exampleSyslog)))
201+
c.Check(handler.LastError, IsNil)
202+
}
203+
204+
func (s *ServerSuite) TestUDPAutomatic5424(c *C) {
205+
handler := new(HandlerMock)
206+
server := NewServer()
207+
server.SetFormat(Automatic)
208+
server.SetHandler(handler)
209+
server.SetTimeout(10)
210+
server.goParseDatagrams()
211+
server.datagramChannel <- DatagramMessage{[]byte(exampleRFC5424Syslog), "0.0.0.0"}
212+
close(server.datagramChannel)
213+
server.Wait()
214+
c.Check(handler.LastLogParts["hostname"], Equals, "mymachine.example.com")
215+
c.Check(handler.LastLogParts["facility"], Equals, 4)
216+
c.Check(handler.LastLogParts["message"], Equals, "'su root' failed for lonvick on /dev/pts/8")
217+
c.Check(handler.LastMessageLength, Equals, int64(len(exampleRFC5424Syslog)))
218+
c.Check(handler.LastError, IsNil)
219+
}
220+
221+
func (s *ServerSuite) TestUDPAutomatic3164Plus6587OctetCount(c *C) {
222+
handler := new(HandlerMock)
223+
server := NewServer()
224+
server.SetFormat(Automatic)
225+
server.SetHandler(handler)
226+
server.SetTimeout(10)
227+
server.goParseDatagrams()
228+
framedSyslog := []byte(fmt.Sprintf("%d %s", len(exampleSyslog), exampleSyslog))
229+
server.datagramChannel <- DatagramMessage{[]byte(framedSyslog), "0.0.0.0"}
230+
close(server.datagramChannel)
231+
server.Wait()
232+
c.Check(handler.LastLogParts["hostname"], Equals, "hostname")
233+
c.Check(handler.LastLogParts["tag"], Equals, "tag")
234+
c.Check(handler.LastLogParts["content"], Equals, "content")
235+
c.Check(handler.LastMessageLength, Equals, int64(len(exampleSyslog)))
236+
c.Check(handler.LastError, IsNil)
237+
}
238+
239+
func (s *ServerSuite) TestUDPAutomatic5424Plus6587OctetCount(c *C) {
240+
handler := new(HandlerMock)
241+
server := NewServer()
242+
server.SetFormat(Automatic)
243+
server.SetHandler(handler)
244+
server.SetTimeout(10)
245+
server.goParseDatagrams()
246+
framedSyslog := []byte(fmt.Sprintf("%d %s", len(exampleRFC5424Syslog), exampleRFC5424Syslog))
247+
server.datagramChannel <- DatagramMessage{[]byte(framedSyslog), "0.0.0.0"}
248+
close(server.datagramChannel)
249+
server.Wait()
250+
c.Check(handler.LastLogParts["hostname"], Equals, "mymachine.example.com")
251+
c.Check(handler.LastLogParts["facility"], Equals, 4)
252+
c.Check(handler.LastLogParts["message"], Equals, "'su root' failed for lonvick on /dev/pts/8")
253+
c.Check(handler.LastMessageLength, Equals, int64(len(exampleRFC5424Syslog)))
254+
c.Check(handler.LastError, IsNil)
255+
}

0 commit comments

Comments
 (0)