@@ -323,12 +323,14 @@ func Test_CancelWorkflowRun(t *testing.T) {
323323 {
324324 name : "successful workflow run cancellation" ,
325325 mockedClient : mock .NewMockedHTTPClient (
326- mock .WithRequestMatch (
326+ mock .WithRequestMatchHandler (
327327 mock.EndpointPattern {
328328 Pattern : "/repos/owner/repo/actions/runs/12345/cancel" ,
329329 Method : "POST" ,
330330 },
331- "" , // Empty response body for 202 Accepted
331+ http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
332+ w .WriteHeader (http .StatusAccepted )
333+ }),
332334 ),
333335 ),
334336 requestArgs : map [string ]any {
@@ -338,6 +340,27 @@ func Test_CancelWorkflowRun(t *testing.T) {
338340 },
339341 expectError : false ,
340342 },
343+ {
344+ name : "conflict when cancelling a workflow run" ,
345+ mockedClient : mock .NewMockedHTTPClient (
346+ mock .WithRequestMatchHandler (
347+ mock.EndpointPattern {
348+ Pattern : "/repos/owner/repo/actions/runs/12345/cancel" ,
349+ Method : "POST" ,
350+ },
351+ http .HandlerFunc (func (w http.ResponseWriter , _ * http.Request ) {
352+ w .WriteHeader (http .StatusConflict )
353+ }),
354+ ),
355+ ),
356+ requestArgs : map [string ]any {
357+ "owner" : "owner" ,
358+ "repo" : "repo" ,
359+ "run_id" : float64 (12345 ),
360+ },
361+ expectError : true ,
362+ expectedErrMsg : "failed to cancel workflow run" ,
363+ },
341364 {
342365 name : "missing required parameter run_id" ,
343366 mockedClient : mock .NewMockedHTTPClient (),
@@ -369,7 +392,7 @@ func Test_CancelWorkflowRun(t *testing.T) {
369392 textContent := getTextResult (t , result )
370393
371394 if tc .expectedErrMsg != "" {
372- assert .Equal (t , tc . expectedErrMsg , textContent . Text )
395+ assert .Contains (t , textContent . Text , tc . expectedErrMsg )
373396 return
374397 }
375398
0 commit comments