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

Function TestRecordingMultipleSimultaneous

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

Source from the content-addressed store, hash-verified

1036}
1037
1038func TestRecordingMultipleSimultaneous(t *testing.T) {
1039 t.Parallel()
1040
1041 logger := slogtest.Make(t, nil)
1042 fake := &fakeDesktop{
1043 startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080},
1044 }
1045 api := agentdesktop.NewAPI(logger, fake, nil)
1046 defer api.Close()
1047
1048 handler := api.Routes()
1049
1050 // Start two recordings with different IDs.
1051 for _, id := range []string{testRecIDConcurrentA, testRecIDConcurrentB} {
1052 body, err := json.Marshal(map[string]string{"recording_id": id})
1053 require.NoError(t, err)
1054 rr := httptest.NewRecorder()
1055 req := httptest.NewRequest(http.MethodPost, "/recording/start", bytes.NewReader(body))
1056 handler.ServeHTTP(rr, req)
1057 require.Equal(t, http.StatusOK, rr.Code)
1058 }
1059
1060 // Stop both and verify each returns its own data.
1061 expected := map[string][]byte{
1062 testRecIDConcurrentA: []byte("fake-mp4-data-" + testRecIDConcurrentA + "-1"),
1063 testRecIDConcurrentB: []byte("fake-mp4-data-" + testRecIDConcurrentB + "-2"),
1064 }
1065 for _, id := range []string{testRecIDConcurrentA, testRecIDConcurrentB} {
1066 body, err := json.Marshal(map[string]string{"recording_id": id})
1067 require.NoError(t, err)
1068 rr := httptest.NewRecorder()
1069 req := httptest.NewRequest(http.MethodPost, "/recording/stop", bytes.NewReader(body))
1070 handler.ServeHTTP(rr, req)
1071 require.Equal(t, http.StatusOK, rr.Code)
1072 parts := parseMultipartParts(t, rr.Header().Get("Content-Type"), rr.Body.Bytes())
1073 assert.Equal(t, expected[id], parts["video/mp4"])
1074 }
1075}
1076
1077func TestRecordingStartMalformedBody(t *testing.T) {
1078 t.Parallel()

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected