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

Function TestRecordingStartAfterCompleted

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

Source from the content-addressed store, hash-verified

1151}
1152
1153func TestRecordingStartAfterCompleted(t *testing.T) {
1154 t.Parallel()
1155
1156 logger := slogtest.Make(t, nil)
1157 fake := &fakeDesktop{
1158 startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080},
1159 }
1160 api := agentdesktop.NewAPI(logger, fake, nil)
1161 defer api.Close()
1162
1163 handler := api.Routes()
1164
1165 // Step 1: Start recording.
1166 startBody, err := json.Marshal(map[string]string{"recording_id": testRecIDRestart})
1167 require.NoError(t, err)
1168 rr := httptest.NewRecorder()
1169 req := httptest.NewRequest(http.MethodPost, "/recording/start", bytes.NewReader(startBody))
1170 handler.ServeHTTP(rr, req)
1171 require.Equal(t, http.StatusOK, rr.Code)
1172
1173 // Step 2: Stop recording (gets first MP4 data).
1174 stopBody, err := json.Marshal(map[string]string{"recording_id": testRecIDRestart})
1175 require.NoError(t, err)
1176 rr = httptest.NewRecorder()
1177 req = httptest.NewRequest(http.MethodPost, "/recording/stop", bytes.NewReader(stopBody))
1178 handler.ServeHTTP(rr, req)
1179 require.Equal(t, http.StatusOK, rr.Code)
1180 firstParts := parseMultipartParts(t, rr.Header().Get("Content-Type"), rr.Body.Bytes())
1181 firstData := firstParts["video/mp4"]
1182 require.NotEmpty(t, firstData)
1183
1184 // Step 3: Start again with the same ID - should succeed
1185 // (old file discarded, new recording started).
1186 rr = httptest.NewRecorder()
1187 req = httptest.NewRequest(http.MethodPost, "/recording/start", bytes.NewReader(startBody))
1188 handler.ServeHTTP(rr, req)
1189 require.Equal(t, http.StatusOK, rr.Code)
1190
1191 // Step 4: Stop again - should return NEW MP4 data.
1192 rr = httptest.NewRecorder()
1193 req = httptest.NewRequest(http.MethodPost, "/recording/stop", bytes.NewReader(stopBody))
1194 handler.ServeHTTP(rr, req)
1195 require.Equal(t, http.StatusOK, rr.Code)
1196 secondParts := parseMultipartParts(t, rr.Header().Get("Content-Type"), rr.Body.Bytes())
1197 secondData := secondParts["video/mp4"]
1198 require.NotEmpty(t, secondData)
1199
1200 // The two recordings should have different data because the
1201 // fake increments a counter on each fresh start.
1202 assert.NotEqual(t, firstData, secondData,
1203 "restarted recording should produce different data")
1204}
1205
1206func TestRecordingStartAfterClose(t *testing.T) {
1207 t.Parallel()

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected