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

Function TestWatchChatGit

coderd/workspaceagents_internal_test.go:165–730  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

163}
164
165func TestWatchChatGit(t *testing.T) {
166 t.Parallel()
167
168 t.Run("ChatWithNoWorkspaceReturns400", func(t *testing.T) {
169 t.Parallel()
170
171 // This test ensures that a chat with no workspace ID
172 // returns a 400 error.
173
174 var (
175 ctx = testutil.Context(t, testutil.WaitShort)
176 logger = slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug).Named("coderd")
177
178 mCtrl = gomock.NewController(t)
179 mDB = dbmock.NewMockStore(mCtrl)
180
181 chatID = uuid.New()
182
183 r = chi.NewMux()
184
185 api = API{
186 ctx: ctx,
187 Options: &Options{
188 AgentInactiveDisconnectTimeout: testutil.WaitShort,
189 Database: mDB,
190 Logger: logger,
191 DeploymentValues: &codersdk.DeploymentValues{},
192 },
193 }
194 )
195
196 // Setup: Return a chat with no workspace ID.
197 mDB.EXPECT().GetChatByID(gomock.Any(), chatID).Return(database.Chat{
198 ID: chatID,
199 OwnerID: uuid.New(),
200 WorkspaceID: uuid.NullUUID{Valid: false},
201 }, nil)
202
203 // And: We mount the HTTP handler.
204 r.With(httpmw.ExtractChatParam(mDB)).
205 Get("/chats/{chat}/stream/git", api.watchChatGit)
206
207 // Given: We create the HTTP server.
208 srv := httptest.NewServer(r)
209 defer srv.Close()
210
211 // When: We make a request.
212 req, err := http.NewRequestWithContext(ctx, http.MethodGet,
213 fmt.Sprintf("%s/chats/%s/stream/git", srv.URL, chatID), nil)
214 require.NoError(t, err)
215
216 resp, err := http.DefaultClient.Do(req)
217 require.NoError(t, err)
218 defer resp.Body.Close()
219
220 // Then: We expect a 400 response.
221 require.Equal(t, http.StatusBadRequest, resp.StatusCode)
222 })

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
ContextFunction · 0.92
NewMockStoreFunction · 0.92
ExtractChatParamFunction · 0.92
NewMockCoordinatorFunction · 0.92
NewFakeCoordinatorFunction · 0.92
NewMockAgentConnFunction · 0.92
NewStreamFunction · 0.92
NowFunction · 0.92
RequireReceiveFunction · 0.92
NewDecoderFunction · 0.92

Tested by

no test coverage detected