mirror of https://github.com/gorilla/websocket
Mirror of https://github.com/gorilla/websocket
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
38 lines
1.1 KiB
// 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 { |
|
if err := wc.WriteMessage(BinaryMessage, []byte(m)); err != nil { |
|
t.Fatalf("write %q: %v", m, err) |
|
} |
|
} |
|
|
|
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) |
|
} |
|
} |
|
} |
|
}
|
|
|