代码拉取完成,页面将自动刷新
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())
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。