Skip to content

Commit 387affa

Browse files
committed
chore: add test stubs
1 parent c86df52 commit 387affa

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

coderd/httpapi/httpapi.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ func WebsocketCloseSprintf(format string, vars ...any) string {
289289
// open a workspace in multiple tabs, the entire UI can start to lock up.
290290
// WebSockets have no such limitation, no matter what HTTP protocol was used to
291291
// establish the connection.
292-
func OneWayWebSocket[T any](rw http.ResponseWriter, r *http.Request) (
293-
sendEvent func(wsEvent T) error,
292+
func OneWayWebSocket[JsonSerializable any](rw http.ResponseWriter, r *http.Request) (
293+
sendEvent func(event JsonSerializable) error,
294294
closed chan struct{},
295295
err error,
296296
) {
@@ -307,7 +307,7 @@ func OneWayWebSocket[T any](rw http.ResponseWriter, r *http.Request) (
307307
Code websocket.StatusCode
308308
Reason string
309309
}
310-
eventC := make(chan T)
310+
eventC := make(chan JsonSerializable)
311311
socketErrC := make(chan SocketError, 1)
312312
closed = make(chan struct{})
313313
go func() {
@@ -354,7 +354,7 @@ func OneWayWebSocket[T any](rw http.ResponseWriter, r *http.Request) (
354354
}
355355
}()
356356

357-
sendEvent = func(event T) error {
357+
sendEvent = func(event JsonSerializable) error {
358358
select {
359359
case eventC <- event:
360360
case <-ctx.Done():

coderd/httpapi/httpapi_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,35 @@ func TestWebsocketCloseMsg(t *testing.T) {
155155
assert.Equal(t, len(trunc), 123)
156156
})
157157
}
158+
159+
func TestOneWayWebSocket(t *testing.T) {
160+
t.Parallel()
161+
162+
t.Run("Produces an error if the socket connection could not be established", func(t *testing.T) {
163+
t.Parallel()
164+
})
165+
166+
t.Run("Returned callback can publish a new event to the WebSocket connection", func(t *testing.T) {
167+
t.Parallel()
168+
})
169+
170+
t.Run("Signals to an outside consumer when the socket has been closed", func(t *testing.T) {
171+
t.Parallel()
172+
})
173+
174+
t.Run("Socket will automatically close if client sends a single message", func(t *testing.T) {
175+
t.Parallel()
176+
})
177+
178+
t.Run("Returned callback returns error if called after socket has been closed", func(t *testing.T) {
179+
t.Parallel()
180+
})
181+
182+
t.Run("Sends a heartbeat to the socket on a fixed internal of time to keep connections alive", func(t *testing.T) {
183+
t.Parallel()
184+
})
185+
186+
t.Run("Renders the socket inert if the parent context cancels", func(t *testing.T) {
187+
t.Parallel()
188+
})
189+
}

0 commit comments

Comments
 (0)