MCPcopy Create free account
hub / github.com/cli/cli / TestRunCancel

Function TestRunCancel

pkg/cmd/run/cancel/cancel_test.go:95–304  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

93}
94
95func 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))

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
JSONResponseFunction · 0.92
StatusStringResponseFunction · 0.92
IndexForFunction · 0.92
TestFunction · 0.92
FromFullNameFunction · 0.92
NewMockPrompterFunction · 0.92
runCancelFunction · 0.85
SetStdoutTTYMethod · 0.80
SetStdinTTYMethod · 0.80

Tested by

no test coverage detected