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

Function TestCloseError

close_test.go:14–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestCloseError(t *testing.T) {
15 t.Parallel()
16
17 testCases := []struct {
18 name string
19 ce CloseError
20 success bool
21 }{
22 {
23 name: "normal",
24 ce: CloseError{
25 Code: StatusNormalClosure,
26 Reason: strings.Repeat("x", maxCloseReason),
27 },
28 success: true,
29 },
30 {
31 name: "bigReason",
32 ce: CloseError{
33 Code: StatusNormalClosure,
34 Reason: strings.Repeat("x", maxCloseReason+1),
35 },
36 success: false,
37 },
38 {
39 name: "bigCode",
40 ce: CloseError{
41 Code: math.MaxUint16,
42 Reason: strings.Repeat("x", maxCloseReason),
43 },
44 success: false,
45 },
46 }
47
48 for _, tc := range testCases {
49 tc := tc
50 t.Run(tc.name, func(t *testing.T) {
51 t.Parallel()
52
53 _, err := tc.ce.bytesErr()
54 if tc.success {
55 assert.Success(t, err)
56 } else {
57 assert.Error(t, err)
58 }
59 })
60 }
61
62 t.Run("Error", func(t *testing.T) {
63 exp := `status = StatusInternalError and reason = "meow"`
64 act := CloseError{
65 Code: StatusInternalError,
66 Reason: "meow",
67 }.Error()
68 assert.Equal(t, "CloseError.Error()", exp, act)
69 })
70}
71

Callers

nothing calls this directly

Calls 5

SuccessFunction · 0.92
ErrorFunction · 0.92
EqualFunction · 0.92
bytesErrMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…