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

Function TestRecordingStopIdempotent

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

Source from the content-addressed store, hash-verified

917}
918
919func TestRecordingStopIdempotent(t *testing.T) {
920 t.Parallel()
921
922 logger := slogtest.Make(t, nil)
923 fake := &fakeDesktop{
924 startCfg: agentdesktop.DisplayConfig{Width: 1920, Height: 1080},
925 }
926 api := agentdesktop.NewAPI(logger, fake, nil)
927 defer api.Close()
928
929 handler := api.Routes()
930
931 // Start recording.
932 startBody, err := json.Marshal(map[string]string{"recording_id": testRecIDStopIdempotent})
933 require.NoError(t, err)
934 rr := httptest.NewRecorder()
935 req := httptest.NewRequest(http.MethodPost, "/recording/start", bytes.NewReader(startBody))
936 handler.ServeHTTP(rr, req)
937 require.Equal(t, http.StatusOK, rr.Code)
938
939 // Stop twice - both should succeed with identical data.
940 var videoParts [2][]byte
941 for i := range 2 {
942 body, err := json.Marshal(map[string]string{"recording_id": testRecIDStopIdempotent})
943 require.NoError(t, err)
944 recorder := httptest.NewRecorder()
945 request := httptest.NewRequest(http.MethodPost, "/recording/stop", bytes.NewReader(body))
946 handler.ServeHTTP(recorder, request)
947 require.Equal(t, http.StatusOK, recorder.Code)
948 parts := parseMultipartParts(t, recorder.Header().Get("Content-Type"), recorder.Body.Bytes())
949 videoParts[i] = parts["video/mp4"]
950 }
951 assert.Equal(t, videoParts[0], videoParts[1])
952}
953
954func TestRecordingStopInvalidIDFormat(t *testing.T) {
955 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