-
Notifications
You must be signed in to change notification settings - Fork 293
/
connection_internal_test.go
73 lines (62 loc) · 1.78 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) quickfixengine.org All rights reserved.
//
// This file may be distributed under the terms of the quickfixengine.org
// license as defined by quickfixengine.org and appearing in the file
// LICENSE included in the packaging of this file.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
// THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE.
//
// See http://www.quickfixengine.org/LICENSE for licensing information.
//
// Contact [email protected] if any conditions of this licensing
// are not clear to you.
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, nullLog{})
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())
}
}
}