(t *testing.T)
| 84 | } |
| 85 | |
| 86 | func TestRunDelete(t *testing.T) { |
| 87 | tests := []struct { |
| 88 | name string |
| 89 | opts *DeleteOptions |
| 90 | httpStubs func(*httpmock.Registry) |
| 91 | prompterStubs func(*prompter.PrompterMock) |
| 92 | wantErr bool |
| 93 | wantOut string |
| 94 | errMsg string |
| 95 | }{ |
| 96 | { |
| 97 | name: "delete run", |
| 98 | opts: &DeleteOptions{ |
| 99 | RunID: "1234", |
| 100 | }, |
| 101 | wantErr: false, |
| 102 | httpStubs: func(reg *httpmock.Registry) { |
| 103 | reg.Register( |
| 104 | httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"), |
| 105 | httpmock.JSONResponse(shared.SuccessfulRun)) |
| 106 | reg.Register( |
| 107 | httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"), |
| 108 | httpmock.JSONResponse(shared.TestWorkflow)) |
| 109 | reg.Register( |
| 110 | httpmock.REST("DELETE", fmt.Sprintf("repos/OWNER/REPO/actions/runs/%d", shared.SuccessfulRun.ID)), |
| 111 | httpmock.StatusStringResponse(204, "")) |
| 112 | }, |
| 113 | wantOut: "✓ Request to delete workflow run submitted.\n", |
| 114 | }, |
| 115 | { |
| 116 | name: "not found", |
| 117 | opts: &DeleteOptions{ |
| 118 | RunID: "1234", |
| 119 | }, |
| 120 | wantErr: true, |
| 121 | errMsg: "could not find any workflow run with ID 1234", |
| 122 | httpStubs: func(reg *httpmock.Registry) { |
| 123 | reg.Register( |
| 124 | httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"), |
| 125 | httpmock.StatusStringResponse(404, "")) |
| 126 | }, |
| 127 | }, |
| 128 | { |
| 129 | name: "prompt", |
| 130 | opts: &DeleteOptions{ |
| 131 | Prompt: true, |
| 132 | }, |
| 133 | prompterStubs: func(pm *prompter.PrompterMock) { |
| 134 | pm.SelectFunc = func(_, _ string, opts []string) (int, error) { |
| 135 | return prompter.IndexFor(opts, "✓ cool commit, CI [trunk] Feb 23, 2021") |
| 136 | } |
| 137 | }, |
| 138 | httpStubs: func(reg *httpmock.Registry) { |
| 139 | reg.Register( |
| 140 | httpmock.REST("GET", "repos/OWNER/REPO/actions/runs"), |
| 141 | httpmock.JSONResponse(shared.RunsPayload{ |
| 142 | TotalCount: 0, |
| 143 | WorkflowRuns: []shared.Run{shared.SuccessfulRun}, |
nothing calls this directly
no test coverage detected