1 Star 0 Fork 0

muicx / quickfix

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
connection_internal_test.go 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
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())
}
}
}
Go
1
https://gitee.com/bradhuang/quickfixgo.git
git@gitee.com:bradhuang/quickfixgo.git
bradhuang
quickfixgo
quickfix
dependabot/go_modules/github.com/mattn/go-sqlite3-1.14.9

搜索帮助