@@ -283,6 +283,92 @@ func TestReportSkipCertVerification(t *testing.T) {
283283 assert .Error (t , err )
284284}
285285
286+ func TestReportCreateArtifactError (t * testing.T ) {
287+ tempDir := t .TempDir ()
288+ artifactPath := filepath .Join (tempDir , "coverage.xml" )
289+ assert .NoError (t , os .WriteFile (artifactPath , []byte ("<coverage/>" ), 0o644 ))
290+
291+ httpClient := & mockHTTPClient {DoFunc : func (req * http.Request ) (* http.Response , error ) {
292+ body , _ := io .ReadAll (req .Body )
293+ _ = req .Body .Close ()
294+ if bytes .Contains (body , []byte ("ArtifactMetadataInput" )) {
295+ payload := `{"data":{"__type":{"inputFields":[]}}}`
296+ return httpResponse (200 , payload ), nil
297+ }
298+ if bytes .Contains (body , []byte ("createArtifact" )) {
299+ payload := `{"data":{"createArtifact":{"ok":false,"message":"","error":"Invalid repository"}}}`
300+ return httpResponse (200 , payload ), nil
301+ }
302+ return httpResponse (400 , `{"error":"unexpected"}` ), nil
303+ }}
304+
305+ git := adapters .NewMockGitClient ()
306+ git .SetHead ("abc123" , "" )
307+ env := adapters .NewMockEnvironment ()
308+ env .Set ("DEEPSOURCE_DSN" , "https://token@localhost:8080" )
309+
310+ svc := NewService (ServiceDeps {
311+ GitClient : git ,
312+ HTTPClient : httpClient ,
313+ FileSystem : adapters .NewOSFileSystem (),
314+ Environment : env ,
315+ Sentry : adapters .NewNoOpSentry (),
316+ Output : adapters .NewBufferOutput (),
317+ Workdir : func () (string , error ) { return tempDir , nil },
318+ })
319+
320+ _ , err := svc .Report (context .Background (), Options {
321+ Analyzer : "test-coverage" ,
322+ Key : "python" ,
323+ ValueFile : artifactPath ,
324+ })
325+ assert .Error (t , err )
326+ assert .Contains (t , err .Error (), "Invalid repository" )
327+ }
328+
329+ func TestReportCreateArtifactEmptyError (t * testing.T ) {
330+ tempDir := t .TempDir ()
331+ artifactPath := filepath .Join (tempDir , "coverage.xml" )
332+ assert .NoError (t , os .WriteFile (artifactPath , []byte ("<coverage/>" ), 0o644 ))
333+
334+ httpClient := & mockHTTPClient {DoFunc : func (req * http.Request ) (* http.Response , error ) {
335+ body , _ := io .ReadAll (req .Body )
336+ _ = req .Body .Close ()
337+ if bytes .Contains (body , []byte ("ArtifactMetadataInput" )) {
338+ payload := `{"data":{"__type":{"inputFields":[]}}}`
339+ return httpResponse (200 , payload ), nil
340+ }
341+ if bytes .Contains (body , []byte ("createArtifact" )) {
342+ payload := `{"data":{"createArtifact":{"ok":false,"message":"","error":""}}}`
343+ return httpResponse (200 , payload ), nil
344+ }
345+ return httpResponse (400 , `{"error":"unexpected"}` ), nil
346+ }}
347+
348+ git := adapters .NewMockGitClient ()
349+ git .SetHead ("abc123" , "" )
350+ env := adapters .NewMockEnvironment ()
351+ env .Set ("DEEPSOURCE_DSN" , "https://token@localhost:8080" )
352+
353+ svc := NewService (ServiceDeps {
354+ GitClient : git ,
355+ HTTPClient : httpClient ,
356+ FileSystem : adapters .NewOSFileSystem (),
357+ Environment : env ,
358+ Sentry : adapters .NewNoOpSentry (),
359+ Output : adapters .NewBufferOutput (),
360+ Workdir : func () (string , error ) { return tempDir , nil },
361+ })
362+
363+ _ , err := svc .Report (context .Background (), Options {
364+ Analyzer : "test-coverage" ,
365+ Key : "python" ,
366+ ValueFile : artifactPath ,
367+ })
368+ assert .Error (t , err )
369+ assert .Contains (t , err .Error (), "raw response" )
370+ }
371+
286372func TestCaptureSkipsUserErrors (t * testing.T ) {
287373 captured := false
288374 mockSentry := & captureSentry {onCapture : func (_ error ) { captured = true }}
0 commit comments