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

Function TestBadDials

dial_test.go:24–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestBadDials(t *testing.T) {
25 t.Parallel()
26
27 t.Run("badReq", func(t *testing.T) {
28 t.Parallel()
29
30 testCases := []struct {
31 name string
32 url string
33 opts *websocket.DialOptions
34 rand util.ReaderFunc
35 nilCtx bool
36 }{
37 {
38 name: "badURL",
39 url: "://noscheme",
40 },
41 {
42 name: "badURLScheme",
43 url: "ftp://nhooyr.io",
44 },
45 {
46 name: "badTLS",
47 url: "wss://totallyfake.nhooyr.io",
48 },
49 {
50 name: "badReader",
51 rand: func(p []byte) (int, error) {
52 return 0, io.EOF
53 },
54 },
55 {
56 name: "nilContext",
57 url: "http://localhost",
58 nilCtx: true,
59 },
60 }
61
62 for _, tc := range testCases {
63 tc := tc
64 t.Run(tc.name, func(t *testing.T) {
65 t.Parallel()
66
67 var ctx context.Context
68 var cancel func()
69 if !tc.nilCtx {
70 ctx, cancel = context.WithTimeout(context.Background(), time.Second*5)
71 defer cancel()
72 }
73
74 if tc.rand == nil {
75 tc.rand = rand.Reader.Read
76 }
77
78 _, _, err := websocket.ExportedDial(ctx, tc.url, tc.opts, tc.rand)
79 assert.Error(t, err)
80 })
81 }

Callers

nothing calls this directly

Calls 4

ErrorFunction · 0.92
DialFunction · 0.92
ContainsFunction · 0.92
mockHTTPClientFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…