MCPcopy Index your code
hub / github.com/coder/websocket / Test_selectSubprotocol

Function Test_selectSubprotocol

accept_test.go:355–408  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

353}
354
355func Test_selectSubprotocol(t *testing.T) {
356 t.Parallel()
357
358 testCases := []struct {
359 name string
360 clientProtocols []string
361 serverProtocols []string
362 negotiated string
363 }{
364 {
365 name: "empty",
366 clientProtocols: nil,
367 serverProtocols: nil,
368 negotiated: "",
369 },
370 {
371 name: "basic",
372 clientProtocols: []string{"echo", "echo2"},
373 serverProtocols: []string{"echo2", "echo"},
374 negotiated: "echo2",
375 },
376 {
377 name: "none",
378 clientProtocols: []string{"echo", "echo3"},
379 serverProtocols: []string{"echo2", "echo4"},
380 negotiated: "",
381 },
382 {
383 name: "fallback",
384 clientProtocols: []string{"echo", "echo3"},
385 serverProtocols: []string{"echo2", "echo3"},
386 negotiated: "echo3",
387 },
388 {
389 name: "clientCasePresered",
390 clientProtocols: []string{"Echo1"},
391 serverProtocols: []string{"echo1"},
392 negotiated: "Echo1",
393 },
394 }
395
396 for _, tc := range testCases {
397 tc := tc
398 t.Run(tc.name, func(t *testing.T) {
399 t.Parallel()
400
401 r := httptest.NewRequest("GET", "/", nil)
402 r.Header.Set("Sec-WebSocket-Protocol", strings.Join(tc.clientProtocols, ","))
403
404 negotiated := selectSubprotocol(r, tc.serverProtocols)
405 assert.Equal(t, "negotiated", tc.negotiated, negotiated)
406 })
407 }
408}
409
410func Test_authenticateOrigin(t *testing.T) {
411 t.Parallel()

Callers

nothing calls this directly

Calls 2

EqualFunction · 0.92
selectSubprotocolFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…