(t *testing.T)
| 1326 | } |
| 1327 | |
| 1328 | func TestHandleRecordingStop_WithThumbnail(t *testing.T) { |
| 1329 | t.Parallel() |
| 1330 | |
| 1331 | logger := slogtest.Make(t, nil) |
| 1332 | // Create a fake JPEG header: 0xFF 0xD8 0xFF followed by 509 zero bytes. |
| 1333 | thumbnail := make([]byte, 512) |
| 1334 | thumbnail[0] = 0xff |
| 1335 | thumbnail[1] = 0xd8 |
| 1336 | thumbnail[2] = 0xff |
| 1337 | |
| 1338 | fake := &fakeDesktop{ |
| 1339 | startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080}, |
| 1340 | thumbnailData: thumbnail, |
| 1341 | } |
| 1342 | api := agentdesktop.NewAPI(logger, fake, nil) |
| 1343 | defer api.Close() |
| 1344 | |
| 1345 | handler := api.Routes() |
| 1346 | |
| 1347 | // Start recording. |
| 1348 | recID := uuid.New().String() |
| 1349 | startBody, err := json.Marshal(map[string]string{"recording_id": recID}) |
| 1350 | require.NoError(t, err) |
| 1351 | rr := httptest.NewRecorder() |
| 1352 | req := httptest.NewRequest(http.MethodPost, "/recording/start", bytes.NewReader(startBody)) |
| 1353 | handler.ServeHTTP(rr, req) |
| 1354 | require.Equal(t, http.StatusOK, rr.Code) |
| 1355 | |
| 1356 | // Stop recording. |
| 1357 | stopBody, err := json.Marshal(map[string]string{"recording_id": recID}) |
| 1358 | require.NoError(t, err) |
| 1359 | rr = httptest.NewRecorder() |
| 1360 | req = httptest.NewRequest(http.MethodPost, "/recording/stop", bytes.NewReader(stopBody)) |
| 1361 | handler.ServeHTTP(rr, req) |
| 1362 | require.Equal(t, http.StatusOK, rr.Code) |
| 1363 | |
| 1364 | // Verify multipart response. |
| 1365 | ct := rr.Header().Get("Content-Type") |
| 1366 | assert.True(t, strings.HasPrefix(ct, "multipart/mixed"), |
| 1367 | "expected multipart/mixed Content-Type, got %s", ct) |
| 1368 | |
| 1369 | parts := parseMultipartParts(t, ct, rr.Body.Bytes()) |
| 1370 | assert.Len(t, parts, 2, "expected exactly 2 parts (video + thumbnail)") |
| 1371 | |
| 1372 | // The fake writes "fake-mp4-data-<id>-<counter>" as the MP4 content. |
| 1373 | expectedMP4 := []byte("fake-mp4-data-" + recID + "-1") |
| 1374 | assert.Equal(t, expectedMP4, parts["video/mp4"]) |
| 1375 | assert.Equal(t, thumbnail, parts["image/jpeg"]) |
| 1376 | } |
| 1377 | |
| 1378 | func TestHandleRecordingStop_NoThumbnail(t *testing.T) { |
| 1379 | t.Parallel() |
nothing calls this directly
no test coverage detected