-
Notifications
You must be signed in to change notification settings - Fork 2
/
stream_test.go
56 lines (47 loc) · 1.38 KB
/
stream_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
package rfc5424
import (
"bytes"
. "gopkg.in/check.v1"
)
var _ = Suite(&StreamTest{})
type StreamTest struct {
}
func (s *StreamTest) TestCanReadAndWrite(c *C) {
stream := bytes.Buffer{}
for i := 0; i < 4; i++ {
m := Message{Priority: i, Timestamp: T("0000-12-31T00:00:00Z")}
nbytes, err := m.WriteTo(&stream)
c.Assert(err, IsNil)
c.Assert(nbytes, Equals, int64(38))
}
c.Assert(string(stream.Bytes()), Equals,
`35 <0>1 0000-12-31T00:00:00Z - - - - -`+
`35 <1>1 0000-12-31T00:00:00Z - - - - -`+
`35 <2>1 0000-12-31T00:00:00Z - - - - -`+
`35 <3>1 0000-12-31T00:00:00Z - - - - -`)
for i := 0; i < 4; i++ {
m := Message{Priority: i << 3}
nbytes, err := m.ReadFrom(&stream)
c.Assert(err, IsNil)
c.Assert(nbytes, Equals, int64(36))
c.Assert(m, DeepEquals, Message{Priority: i,
Timestamp: T("0000-12-31T00:00:00Z"),
StructuredData: []StructuredData{}})
}
}
func (s *StreamTest) TestRejectsInvalidStream(c *C) {
stream := bytes.NewBufferString(`99 <0>1 0000-12-31T00:00:00Z - - - - -`)
for i := 0; i < 4; i++ {
m := Message{Priority: i << 3}
_, err := m.ReadFrom(stream)
c.Assert(err, Not(IsNil))
}
}
func (s *StreamTest) TestRejectsInvalidStream2(c *C) {
stream := bytes.NewBufferString(`0 <0>1 0000-12-31T00:00:00Z - - - - -`)
for i := 0; i < 4; i++ {
m := Message{Priority: i << 3}
_, err := m.ReadFrom(stream)
c.Assert(err, Not(IsNil))
}
}