forked from quickfixgo/quickfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection_internal_test.go
58 lines (48 loc) · 1.2 KB
/
connection_internal_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
57
58
package quickfix
import (
"bytes"
"strings"
"testing"
)
func TestWriteLoop(t *testing.T) {
writer := bytes.NewBufferString("")
msgOut := make(chan []byte)
go func() {
msgOut <- []byte("test msg 1 ")
msgOut <- []byte("test msg 2 ")
msgOut <- []byte("test msg 3")
close(msgOut)
}()
writeLoop(writer, msgOut, nullLog{})
expected := "test msg 1 test msg 2 test msg 3"
if writer.String() != expected {
t.Errorf("expected %v got %v", expected, writer.String())
}
}
func TestReadLoop(t *testing.T) {
msgIn := make(chan fixIn)
stream := "hello8=FIX.4.09=5blah10=103garbage8=FIX.4.09=4foo10=103"
parser := newParser(strings.NewReader(stream))
go readLoop(parser, msgIn)
var tests = []struct {
expectedMsg string
channelClosed bool
}{
{expectedMsg: "8=FIX.4.09=5blah10=103"},
{expectedMsg: "8=FIX.4.09=4foo10=103"},
{channelClosed: true},
}
for _, test := range tests {
msg, ok := <-msgIn
switch {
case !ok && !test.channelClosed:
t.Error("Channel unexpectedly closed")
fallthrough
case !ok && test.channelClosed:
continue
}
if msg.bytes.String() != test.expectedMsg {
t.Errorf("Expected %v got %v", test.expectedMsg, msg.bytes.String())
}
}
}