(t *testing.T)
| 1151 | } |
| 1152 | |
| 1153 | func 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 | |
| 1206 | func TestRecordingStartAfterClose(t *testing.T) { |
| 1207 | t.Parallel() |
nothing calls this directly
no test coverage detected