MCPcopy
hub / github.com/gorilla/websocket / TestJoinMessages

Function TestJoinMessages

join_test.go:14–36  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestJoinMessages(t *testing.T) {
15 messages := []string{"a", "bc", "def", "ghij", "klmno", "0", "12", "345", "6789"}
16 for _, readChunk := range []int{1, 2, 3, 4, 5, 6, 7} {
17 for _, term := range []string{"", ","} {
18 var connBuf bytes.Buffer
19 wc := newTestConn(nil, &connBuf, true)
20 rc := newTestConn(&connBuf, nil, false)
21 for _, m := range messages {
22 wc.WriteMessage(BinaryMessage, []byte(m))
23 }
24
25 var result bytes.Buffer
26 _, err := io.CopyBuffer(&result, JoinMessages(rc, term), make([]byte, readChunk))
27 if IsUnexpectedCloseError(err, CloseAbnormalClosure) {
28 t.Errorf("readChunk=%d, term=%q: unexpected error %v", readChunk, term, err)
29 }
30 want := strings.Join(messages, term) + term
31 if result.String() != want {
32 t.Errorf("readChunk=%d, term=%q, got %q, want %q", readChunk, term, result.String(), want)
33 }
34 }
35 }
36}

Callers

nothing calls this directly

Calls 5

newTestConnFunction · 0.85
JoinMessagesFunction · 0.85
IsUnexpectedCloseErrorFunction · 0.85
WriteMessageMethod · 0.80
StringMethod · 0.80

Tested by

no test coverage detected