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

Function TestHandleRecordingStop_WithThumbnail

agent/x/agentdesktop/api_test.go:1328–1376  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1326}
1327
1328func 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
1378func TestHandleRecordingStop_NoThumbnail(t *testing.T) {
1379 t.Parallel()

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
RoutesMethod · 0.95
NewAPIFunction · 0.92
parseMultipartPartsFunction · 0.85
NewMethod · 0.65
GetMethod · 0.65
StringMethod · 0.45
MarshalMethod · 0.45
ServeHTTPMethod · 0.45
EqualMethod · 0.45
HeaderMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected