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

Function Test_parseClosePayload

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

Source from the content-addressed store, hash-verified

70}
71
72func Test_parseClosePayload(t *testing.T) {
73 t.Parallel()
74
75 testCases := []struct {
76 name string
77 p []byte
78 success bool
79 ce CloseError
80 }{
81 {
82 name: "normal",
83 p: append([]byte{0x3, 0xE8}, []byte("hello")...),
84 success: true,
85 ce: CloseError{
86 Code: StatusNormalClosure,
87 Reason: "hello",
88 },
89 },
90 {
91 name: "nothing",
92 success: true,
93 ce: CloseError{
94 Code: StatusNoStatusRcvd,
95 },
96 },
97 {
98 name: "oneByte",
99 p: []byte{0},
100 success: false,
101 },
102 {
103 name: "badStatusCode",
104 p: []byte{0x17, 0x70},
105 success: false,
106 },
107 }
108
109 for _, tc := range testCases {
110 tc := tc
111 t.Run(tc.name, func(t *testing.T) {
112 t.Parallel()
113
114 ce, err := parseClosePayload(tc.p)
115 if tc.success {
116 assert.Success(t, err)
117 assert.Equal(t, "close payload", tc.ce, ce)
118 } else {
119 assert.Error(t, err)
120 }
121 })
122 }
123}
124
125func Test_validWireCloseCode(t *testing.T) {
126 t.Parallel()

Callers

nothing calls this directly

Calls 4

SuccessFunction · 0.92
EqualFunction · 0.92
ErrorFunction · 0.92
parseClosePayloadFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…