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

Function TestCloseFrameBeforeFinalMessageFrame

conn_test.go:352–378  ·  conn_test.go::TestCloseFrameBeforeFinalMessageFrame
(t *testing.T)

Source from the content-addressed store, hash-verified

350}
351
352func TestCloseFrameBeforeFinalMessageFrame(t *testing.T) {
353 const bufSize = 512
354
355 expectedErr := &CloseError{Code: CloseNormalClosure, Text: "hello"}
356
357 var b1, b2 bytes.Buffer
358 wc := newConn(&fakeNetConn{Reader: nil, Writer: &b1}, false, 1024, bufSize, nil, nil, nil)
359 rc := newTestConn(&b1, &b2, true)
360
361 w, _ := wc.NextWriter(BinaryMessage)
362 w.Write(make([]byte, bufSize+bufSize/2))
363 wc.WriteControl(CloseMessage, FormatCloseMessage(expectedErr.Code, expectedErr.Text), time.Now().Add(10*time.Second))
364 w.Close()
365
366 op, r, err := rc.NextReader()
367 if op != BinaryMessage || err != nil {
368 t.Fatalf("NextReader() returned %d, %v", op, err)
369 }
370 _, err = io.Copy(ioutil.Discard, r)
371 if !reflect.DeepEqual(err, expectedErr) {
372 t.Fatalf("io.Copy() returned %v, want %v", err, expectedErr)
373 }
374 _, _, err = rc.NextReader()
375 if !reflect.DeepEqual(err, expectedErr) {
376 t.Fatalf("NextReader() returned %v, want %v", err, expectedErr)
377 }
378}
379
380func TestEOFWithinFrame(t *testing.T) {
381 const bufSize = 64

Callers

nothing calls this directly

Calls 8

newConnFunction · 0.85
newTestConnFunction · 0.85
FormatCloseMessageFunction · 0.85
NextWriterMethod · 0.80
WriteControlMethod · 0.80
NextReaderMethod · 0.80
WriteMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected