forked from go-stomp/stomp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
writer_test.go
48 lines (37 loc) · 1003 Bytes
/
writer_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
package stomp
import (
"bytes"
//. "gopkg.in/check.v1"
"strings"
)
type WriterSuite struct{}
var _ = Suite(&WriterSuite{})
func (s *WriterSuite) TestWrites(c *C) {
var frameTexts = []string{
"CONNECT\nlogin:xxx\npasscode:yyy\n\n\x00",
"SEND\n" +
"destination:/queue/request\n" +
"tx:1\n" +
"content-length:5\n" +
"\n\x00\x01\x02\x03\x04\x00",
"SEND\ndestination:x\n\nABCD\x00",
}
for _, frameText := range frameTexts {
writeToBufferAndCheck(c, frameText)
}
}
// TODO(jpj): the order of the header entries is dependent on the
// hash function -- so this test is a bit brittle.
func writeToBufferAndCheck(c *C, frameText string) {
reader := NewReader(strings.NewReader(frameText))
frame, err := reader.Read()
c.Assert(err, IsNil)
c.Assert(frame, NotNil)
var b bytes.Buffer
var writer = NewWriter(&b)
err = writer.Write(frame)
c.Assert(err, IsNil)
newFrameText := b.String()
c.Check(newFrameText, Equals, frameText)
c.Check(b.String(), Equals, frameText)
}