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

Function TestNextProtos

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

Source from the content-addressed store, hash-verified

1099 }
1100}
1101func TestNextProtos(t *testing.T) {
1102 ts := httptest.NewUnstartedServer(
1103 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}),
1104 )
1105 ts.EnableHTTP2 = true
1106 ts.StartTLS()
1107 defer ts.Close()
1108
1109 d := Dialer{
1110 TLSClientConfig: ts.Client().Transport.(*http.Transport).TLSClientConfig,
1111 }
1112
1113 r, err := ts.Client().Get(ts.URL)
1114 if err != nil {
1115 t.Fatalf("Get: %v", err)
1116 }
1117 r.Body.Close()
1118
1119 // Asserts that Dialer.TLSClientConfig.NextProtos contains "h2"
1120 // after the Client.Get call from net/http above.
1121 var containsHTTP2 bool = false
1122 for _, proto := range d.TLSClientConfig.NextProtos {
1123 if proto == "h2" {
1124 containsHTTP2 = true
1125 }
1126 }
1127 if !containsHTTP2 {
1128 t.Fatalf("Dialer.TLSClientConfig.NextProtos does not contain \"h2\"")
1129 }
1130
1131 _, _, err = d.Dial(makeWsProto(ts.URL), nil)
1132 if err == nil {
1133 t.Fatalf("Dial succeeded, expect fail ")
1134 }
1135}

Callers

nothing calls this directly

Calls 4

DialMethod · 0.95
makeWsProtoFunction · 0.85
GetMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected