MCPcopy
hub / github.com/coder/websocket / TestGin

Function TestGin

internal/thirdparty/gin_test.go:20–52  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestGin(t *testing.T) {
21 t.Parallel()
22
23 gin.SetMode(gin.ReleaseMode)
24 r := gin.New()
25 r.GET("/", func(ginCtx *gin.Context) {
26 err := echoServer(ginCtx.Writer, ginCtx.Request, nil)
27 if err != nil {
28 t.Error(err)
29 }
30 })
31
32 s := httptest.NewServer(r)
33 defer s.Close()
34
35 ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
36 defer cancel()
37
38 c, _, err := websocket.Dial(ctx, s.URL, nil)
39 assert.Success(t, err)
40 defer c.Close(websocket.StatusInternalError, "")
41
42 err = wsjson.Write(ctx, c, "hello")
43 assert.Success(t, err)
44
45 var v any
46 err = wsjson.Read(ctx, c, &v)
47 assert.Success(t, err)
48 assert.Equal(t, "read msg", "hello", v)
49
50 err = c.Close(websocket.StatusNormalClosure, "")
51 assert.Success(t, err)
52}
53
54func echoServer(w http.ResponseWriter, r *http.Request, opts *websocket.AcceptOptions) (err error) {
55 defer errd.Wrap(&err, "echo server failed")

Callers

nothing calls this directly

Calls 8

DialFunction · 0.92
SuccessFunction · 0.92
WriteFunction · 0.92
ReadFunction · 0.92
EqualFunction · 0.92
echoServerFunction · 0.70
ErrorMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…