(t *testing.T)
| 218 | } |
| 219 | |
| 220 | func 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() |
nothing calls this directly
no test coverage detected