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

Function Test_echoServer

internal/examples/echo/server_test.go:15–54  ·  view source on GitHub ↗

Test_echoServer tests the echoServer by sending it 5 different messages and ensuring the responses all match.

(t *testing.T)

Source from the content-addressed store, hash-verified

13// Test_echoServer tests the echoServer by sending it 5 different messages
14// and ensuring the responses all match.
15func Test_echoServer(t *testing.T) {
16 t.Parallel()
17
18 s := httptest.NewServer(echoServer{
19 logf: t.Logf,
20 })
21 defer s.Close()
22
23 ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
24 defer cancel()
25
26 c, _, err := websocket.Dial(ctx, s.URL, &websocket.DialOptions{
27 Subprotocols: []string{"echo"},
28 })
29 if err != nil {
30 t.Fatal(err)
31 }
32 defer c.Close(websocket.StatusInternalError, "the sky is falling")
33
34 for i := 0; i < 5; i++ {
35 err = wsjson.Write(ctx, c, map[string]int{
36 "i": i,
37 })
38 if err != nil {
39 t.Fatal(err)
40 }
41
42 v := map[string]int{}
43 err = wsjson.Read(ctx, c, &v)
44 if err != nil {
45 t.Fatal(err)
46 }
47
48 if v["i"] != i {
49 t.Fatalf("expected %v but got %v", i, v)
50 }
51 }
52
53 c.Close(websocket.StatusNormalClosure, "")
54}

Callers

nothing calls this directly

Calls 4

DialFunction · 0.92
WriteFunction · 0.92
ReadFunction · 0.92
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…