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

Function TestRespOnBadHandshake

client_server_test.go:528–560  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

526}
527
528func TestRespOnBadHandshake(t *testing.T) {
529 const expectedStatus = http.StatusGone
530 const expectedBody = "This is the response body."
531
532 s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
533 w.WriteHeader(expectedStatus)
534 io.WriteString(w, expectedBody)
535 }))
536 defer s.Close()
537
538 ws, resp, err := cstDialer.Dial(makeWsProto(s.URL), nil)
539 if err == nil {
540 ws.Close()
541 t.Fatalf("Dial: nil")
542 }
543
544 if resp == nil {
545 t.Fatalf("resp=nil, err=%v", err)
546 }
547
548 if resp.StatusCode != expectedStatus {
549 t.Errorf("resp.StatusCode=%d, want %d", resp.StatusCode, expectedStatus)
550 }
551
552 p, err := ioutil.ReadAll(resp.Body)
553 if err != nil {
554 t.Fatalf("ReadFull(resp.Body) returned error %v", err)
555 }
556
557 if string(p) != expectedBody {
558 t.Errorf("resp.Body=%s, want %s", p, expectedBody)
559 }
560}
561
562type testLogWriter struct {
563 t *testing.T

Callers

nothing calls this directly

Calls 4

makeWsProtoFunction · 0.85
WriteStringMethod · 0.80
DialMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected