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

Function TestStartProcess

agent/agentproc/api_test.go:220–474  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

218}
219
220func TestStartProcess(t *testing.T) {
221 t.Parallel()
222
223 t.Run("ForegroundCommand", func(t *testing.T) {
224 t.Parallel()
225
226 handler := newTestAPI(t)
227 w := postStart(t, handler, workspacesdk.StartProcessRequest{
228 Command: "echo hello",
229 })
230 require.Equal(t, http.StatusOK, w.Code)
231
232 var resp workspacesdk.StartProcessResponse
233 err := json.NewDecoder(w.Body).Decode(&resp)
234 require.NoError(t, err)
235 require.True(t, resp.Started)
236 require.NotEmpty(t, resp.ID)
237 })
238
239 t.Run("BackgroundCommand", func(t *testing.T) {
240 t.Parallel()
241
242 handler := newTestAPI(t)
243 w := postStart(t, handler, workspacesdk.StartProcessRequest{
244 Command: "echo background",
245 Background: true,
246 })
247 require.Equal(t, http.StatusOK, w.Code)
248
249 var resp workspacesdk.StartProcessResponse
250 err := json.NewDecoder(w.Body).Decode(&resp)
251 require.NoError(t, err)
252 require.True(t, resp.Started)
253 require.NotEmpty(t, resp.ID)
254 })
255
256 t.Run("EmptyCommand", func(t *testing.T) {
257 t.Parallel()
258
259 handler := newTestAPI(t)
260 w := postStart(t, handler, workspacesdk.StartProcessRequest{
261 Command: "",
262 })
263 require.Equal(t, http.StatusBadRequest, w.Code)
264
265 var resp codersdk.Response
266 err := json.NewDecoder(w.Body).Decode(&resp)
267 require.NoError(t, err)
268 require.Contains(t, resp.Message, "Command is required")
269 })
270
271 t.Run("MalformedJSON", func(t *testing.T) {
272 t.Parallel()
273
274 handler := newTestAPI(t)
275
276 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
277 defer cancel()

Callers

nothing calls this directly

Calls 13

postStartFunction · 0.85
startAndGetIDFunction · 0.85
waitForExitFunction · 0.85
getListFunction · 0.85
newTestAPIWithOptionsFunction · 0.85
newTestAPIWithUpdateEnvFunction · 0.85
NotEmptyMethod · 0.80
newTestAPIFunction · 0.70
RunMethod · 0.65
TempDirMethod · 0.65
EqualMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected