| 824 | } |
| 825 | |
| 826 | func TestRecordingStartStop(t *testing.T) { |
| 827 | t.Parallel() |
| 828 | |
| 829 | logger := slogtest.Make(t, nil) |
| 830 | fake := &fakeDesktop{ |
| 831 | startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080}, |
| 832 | } |
| 833 | api := agentdesktop.NewAPI(logger, fake, nil) |
| 834 | defer api.Close() |
| 835 | |
| 836 | handler := api.Routes() |
| 837 | |
| 838 | // Start recording. |
| 839 | startBody, err := json.Marshal(map[string]string{"recording_id": testRecIDDefault}) |
| 840 | require.NoError(t, err) |
| 841 | rr := httptest.NewRecorder() |
| 842 | req := httptest.NewRequest(http.MethodPost, "/recording/start", bytes.NewReader(startBody)) |
| 843 | handler.ServeHTTP(rr, req) |
| 844 | require.Equal(t, http.StatusOK, rr.Code) |
| 845 | |
| 846 | // Stop recording. |
| 847 | stopBody, err := json.Marshal(map[string]string{"recording_id": testRecIDDefault}) |
| 848 | require.NoError(t, err) |
| 849 | rr = httptest.NewRecorder() |
| 850 | req = httptest.NewRequest(http.MethodPost, "/recording/stop", bytes.NewReader(stopBody)) |
| 851 | handler.ServeHTTP(rr, req) |
| 852 | require.Equal(t, http.StatusOK, rr.Code) |
| 853 | parts := parseMultipartParts(t, rr.Header().Get("Content-Type"), rr.Body.Bytes()) |
| 854 | assert.Equal(t, []byte("fake-mp4-data-"+testRecIDDefault+"-1"), parts["video/mp4"]) |
| 855 | } |
| 856 | |
| 857 | func TestRecordingStartFails(t *testing.T) { |
| 858 | t.Parallel() |