| 884 | } |
| 885 | |
| 886 | func TestRecordingStartIdempotent(t *testing.T) { |
| 887 | t.Parallel() |
| 888 | |
| 889 | logger := slogtest.Make(t, nil) |
| 890 | fake := &fakeDesktop{ |
| 891 | startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080}, |
| 892 | } |
| 893 | api := agentdesktop.NewAPI(logger, fake, nil) |
| 894 | defer api.Close() |
| 895 | |
| 896 | handler := api.Routes() |
| 897 | |
| 898 | // Start same recording twice - both should succeed. |
| 899 | for range 2 { |
| 900 | body, err := json.Marshal(map[string]string{"recording_id": testRecIDStartIdempotent}) |
| 901 | require.NoError(t, err) |
| 902 | rr := httptest.NewRecorder() |
| 903 | req := httptest.NewRequest(http.MethodPost, "/recording/start", bytes.NewReader(body)) |
| 904 | handler.ServeHTTP(rr, req) |
| 905 | require.Equal(t, http.StatusOK, rr.Code) |
| 906 | } |
| 907 | |
| 908 | // Stop once, verify normal response. |
| 909 | stopBody, err := json.Marshal(map[string]string{"recording_id": testRecIDStartIdempotent}) |
| 910 | require.NoError(t, err) |
| 911 | rr := httptest.NewRecorder() |
| 912 | req := httptest.NewRequest(http.MethodPost, "/recording/stop", bytes.NewReader(stopBody)) |
| 913 | handler.ServeHTTP(rr, req) |
| 914 | require.Equal(t, http.StatusOK, rr.Code) |
| 915 | parts := parseMultipartParts(t, rr.Header().Get("Content-Type"), rr.Body.Bytes()) |
| 916 | assert.Equal(t, []byte("fake-mp4-data-"+testRecIDStartIdempotent+"-1"), parts["video/mp4"]) |
| 917 | } |
| 918 | |
| 919 | func TestRecordingStopIdempotent(t *testing.T) { |
| 920 | t.Parallel() |