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

Function TestHandleRecordingStop_OversizedThumbnail

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

Source from the content-addressed store, hash-verified

1417}
1418
1419func TestHandleRecordingStop_OversizedThumbnail(t *testing.T) {
1420 t.Parallel()
1421
1422 logger := slogtest.Make(t, nil)
1423 // Create thumbnail data that exceeds MaxThumbnailSize.
1424 oversizedThumb := make([]byte, workspacesdk.MaxThumbnailSize+1)
1425 oversizedThumb[0] = 0xff
1426 oversizedThumb[1] = 0xd8
1427 oversizedThumb[2] = 0xff
1428
1429 fake := &fakeDesktop{
1430 startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080},
1431 thumbnailData: oversizedThumb,
1432 }
1433 api := agentdesktop.NewAPI(logger, fake, nil)
1434 defer api.Close()
1435
1436 handler := api.Routes()
1437
1438 // Start recording.
1439 recID := uuid.New().String()
1440 startBody, err := json.Marshal(map[string]string{"recording_id": recID})
1441 require.NoError(t, err)
1442 rr := httptest.NewRecorder()
1443 req := httptest.NewRequest(http.MethodPost, "/recording/start", bytes.NewReader(startBody))
1444 handler.ServeHTTP(rr, req)
1445 require.Equal(t, http.StatusOK, rr.Code)
1446
1447 // Stop recording.
1448 stopBody, err := json.Marshal(map[string]string{"recording_id": recID})
1449 require.NoError(t, err)
1450 rr = httptest.NewRecorder()
1451 req = httptest.NewRequest(http.MethodPost, "/recording/stop", bytes.NewReader(stopBody))
1452 handler.ServeHTTP(rr, req)
1453 require.Equal(t, http.StatusOK, rr.Code)
1454
1455 // Verify multipart response contains only the video part.
1456 ct := rr.Header().Get("Content-Type")
1457 assert.True(t, strings.HasPrefix(ct, "multipart/mixed"),
1458 "expected multipart/mixed Content-Type, got %s", ct)
1459
1460 parts := parseMultipartParts(t, ct, rr.Body.Bytes())
1461 assert.Len(t, parts, 1, "expected exactly 1 part (video only, oversized thumbnail discarded)")
1462
1463 expectedMP4 := []byte("fake-mp4-data-" + recID + "-1")
1464 assert.Equal(t, expectedMP4, parts["video/mp4"])
1465}

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