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

Function TestRecordingStartIdempotent

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

Source from the content-addressed store, hash-verified

884}
885
886func 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
919func TestRecordingStopIdempotent(t *testing.T) {
920 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