@@ -65,3 +65,41 @@ def test_cli(env: dict[str, str], monkeypatch: pytest.MonkeyPatch) -> None:
6565 "test_language" : None ,
6666 "files" : (str (REPORT_XML ),),
6767 }
68+
69+
70+ def test_upload_error (monkeypatch : pytest .MonkeyPatch ) -> None :
71+ for key , value in {
72+ "GITHUB_EVENT_NAME" : "push" ,
73+ "GITHUB_ACTIONS" : "true" ,
74+ "MERGIFY_API_URL" : "https://api.mergify.com" ,
75+ "MERGIFY_TOKEN" : "abc" ,
76+ "GITHUB_REPOSITORY" : "user/repo" ,
77+ "GITHUB_SHA" : "3af96aa24f1d32fcfbb7067793cacc6dc0c6b199" ,
78+ "GITHUB_WORKFLOW" : "JOB" ,
79+ }.items ():
80+ monkeypatch .setenv (key , value )
81+
82+ runner = testing .CliRunner ()
83+
84+ with mock .patch .object (
85+ upload ,
86+ "upload" ,
87+ mock .AsyncMock (),
88+ ) as mocked_upload :
89+ mocked_upload .side_effect = Exception ("Upload failed" )
90+ result = runner .invoke (
91+ cli_junit_upload .junit_upload ,
92+ [str (REPORT_XML )],
93+ )
94+ assert result .exit_code == 0 , (result .stdout , result .stderr )
95+ assert result .stderr == "Error uploading JUnit XML reports: Upload failed\n "
96+ assert not result .stdout
97+ assert mocked_upload .call_count == 1
98+ assert mocked_upload .call_args .kwargs == {
99+ "api_url" : "https://api.mergify.com" ,
100+ "token" : "abc" ,
101+ "repository" : "user/repo" ,
102+ "test_framework" : None ,
103+ "test_language" : None ,
104+ "files" : (str (REPORT_XML ),),
105+ }
0 commit comments