Skip to content

Commit aa2ee9e

Browse files
committed
chore: get first test passing
1 parent 387affa commit aa2ee9e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

coderd/httpapi/httpapi_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
"github.com/coder/coder/v2/coderd/httpapi"
1818
"github.com/coder/coder/v2/codersdk"
19+
"github.com/coder/coder/v2/testutil"
1920
)
2021

2122
func TestInternalServerError(t *testing.T) {
@@ -158,9 +159,25 @@ func TestWebsocketCloseMsg(t *testing.T) {
158159

159160
func TestOneWayWebSocket(t *testing.T) {
160161
t.Parallel()
162+
url := "ws://www.fake-website.com/logs"
161163

162164
t.Run("Produces an error if the socket connection could not be established", func(t *testing.T) {
163165
t.Parallel()
166+
167+
// WebSocket connections cannot be created on HTTP/1.0 and below
168+
ctx := testutil.Context(t, testutil.WaitShort)
169+
r, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
170+
require.NoError(t, err)
171+
r.ProtoMajor = 1
172+
r.ProtoMinor = 0
173+
r.Proto = "HTTP/1.0"
174+
175+
_, _, err = httpapi.OneWayWebSocket[any](httptest.NewRecorder(), r)
176+
require.ErrorContains(
177+
t,
178+
err,
179+
"WebSocket protocol violation: handshake request must be at least HTTP/1.1:",
180+
)
164181
})
165182

166183
t.Run("Returned callback can publish a new event to the WebSocket connection", func(t *testing.T) {
@@ -183,7 +200,7 @@ func TestOneWayWebSocket(t *testing.T) {
183200
t.Parallel()
184201
})
185202

186-
t.Run("Renders the socket inert if the parent context cancels", func(t *testing.T) {
203+
t.Run("Renders the socket inert if the request context cancels", func(t *testing.T) {
187204
t.Parallel()
188205
})
189206
}

0 commit comments

Comments
 (0)