(t *testing.T)
| 93 | } |
| 94 | |
| 95 | func TestRunCancel(t *testing.T) { |
| 96 | inProgressRun := shared.TestRun(1234, shared.InProgress, "") |
| 97 | completedRun := shared.TestRun(4567, shared.Completed, shared.Failure) |
| 98 | tests := []struct { |
| 99 | name string |
| 100 | httpStubs func(*httpmock.Registry) |
| 101 | promptStubs func(*prompter.MockPrompter) |
| 102 | opts *CancelOptions |
| 103 | wantErr bool |
| 104 | wantOut string |
| 105 | errMsg string |
| 106 | }{ |
| 107 | { |
| 108 | name: "cancel run", |
| 109 | opts: &CancelOptions{ |
| 110 | RunID: "1234", |
| 111 | }, |
| 112 | wantErr: false, |
| 113 | httpStubs: func(reg *httpmock.Registry) { |
| 114 | reg.Register( |
| 115 | httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"), |
| 116 | httpmock.JSONResponse(inProgressRun)) |
| 117 | reg.Register( |
| 118 | httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"), |
| 119 | httpmock.JSONResponse(shared.TestWorkflow)) |
| 120 | reg.Register( |
| 121 | httpmock.REST("POST", "repos/OWNER/REPO/actions/runs/1234/cancel"), |
| 122 | httpmock.StatusStringResponse(202, "{}")) |
| 123 | }, |
| 124 | wantOut: "✓ Request to cancel workflow 1234 submitted.\n", |
| 125 | }, |
| 126 | { |
| 127 | name: "not found", |
| 128 | opts: &CancelOptions{ |
| 129 | RunID: "1234", |
| 130 | }, |
| 131 | wantErr: true, |
| 132 | errMsg: "Could not find any workflow run with ID 1234", |
| 133 | httpStubs: func(reg *httpmock.Registry) { |
| 134 | reg.Register( |
| 135 | httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"), |
| 136 | httpmock.StatusStringResponse(404, "")) |
| 137 | }, |
| 138 | }, |
| 139 | { |
| 140 | name: "completed", |
| 141 | opts: &CancelOptions{ |
| 142 | RunID: "4567", |
| 143 | }, |
| 144 | wantErr: true, |
| 145 | errMsg: "Cannot cancel a workflow run that is completed", |
| 146 | httpStubs: func(reg *httpmock.Registry) { |
| 147 | reg.Register( |
| 148 | httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/4567"), |
| 149 | httpmock.JSONResponse(completedRun)) |
| 150 | reg.Register( |
| 151 | httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"), |
| 152 | httpmock.JSONResponse(shared.TestWorkflow)) |
nothing calls this directly
no test coverage detected