加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/gorilla/websocket
克隆/下载
join_test.go 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
apoorvajagtap 提交于 2024-06-14 08:23 . Reverts to v1.5.0
// Copyright 2019 The Gorilla WebSocket Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package websocket
import (
"bytes"
"io"
"strings"
"testing"
)
func TestJoinMessages(t *testing.T) {
messages := []string{"a", "bc", "def", "ghij", "klmno", "0", "12", "345", "6789"}
for _, readChunk := range []int{1, 2, 3, 4, 5, 6, 7} {
for _, term := range []string{"", ","} {
var connBuf bytes.Buffer
wc := newTestConn(nil, &connBuf, true)
rc := newTestConn(&connBuf, nil, false)
for _, m := range messages {
wc.WriteMessage(BinaryMessage, []byte(m))
}
var result bytes.Buffer
_, err := io.CopyBuffer(&result, JoinMessages(rc, term), make([]byte, readChunk))
if IsUnexpectedCloseError(err, CloseAbnormalClosure) {
t.Errorf("readChunk=%d, term=%q: unexpected error %v", readChunk, term, err)
}
want := strings.Join(messages, term) + term
if result.String() != want {
t.Errorf("readChunk=%d, term=%q, got %q, want %q", readChunk, term, result.String(), want)
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化