MCPcopy Index your code
hub / github.com/coder/coder / TestWebsocketCloseMsg

Function TestWebsocketCloseMsg

coderd/httpapi/httpapi_test.go:132–163  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

130}
131
132func TestWebsocketCloseMsg(t *testing.T) {
133 t.Parallel()
134
135 t.Run("Sprintf", func(t *testing.T) {
136 t.Parallel()
137
138 var (
139 msg = "this is my message %q %q"
140 opts = []any{"colin", "kyle"}
141 )
142
143 expected := fmt.Sprintf(msg, opts...)
144 got := httpapi.WebsocketCloseSprintf(msg, opts...)
145 assert.Equal(t, expected, got)
146 })
147
148 t.Run("TruncateSingleByteCharacters", func(t *testing.T) {
149 t.Parallel()
150
151 msg := strings.Repeat("d", 255)
152 trunc := httpapi.WebsocketCloseSprintf("%s", msg)
153 assert.Equal(t, len(trunc), 123)
154 })
155
156 t.Run("TruncateMultiByteCharacters", func(t *testing.T) {
157 t.Parallel()
158
159 msg := strings.Repeat("こんにちは", 10)
160 trunc := httpapi.WebsocketCloseSprintf("%s", msg)
161 assert.Equal(t, len(trunc), 123)
162 })
163}
164
165// Our WebSocket library accepts any arbitrary ResponseWriter at the type level,
166// but the writer must also implement http.Hijacker for long-lived connections.

Callers

nothing calls this directly

Calls 3

WebsocketCloseSprintfFunction · 0.92
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected