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

Function TestPrintFailure

pkg/cmd/issue/artifact/shared/results_test.go:176–280  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

174}
175
176func TestPrintFailure(t *testing.T) {
177 artifactURL := func(number string) *url.URL {
178 u, err := url.Parse("https://api.github.com/repos/monalisa/monas-cafe/issues/142/artifacts/" + number)
179 require.NoError(t, err)
180 return u
181 }
182 apiError := func(status int, message string, number string) error {
183 return api.HTTPError{HTTPError: &ghAPI.HTTPError{StatusCode: status, Message: message, RequestURL: artifactURL(number)}}
184 }
185
186 tests := []struct {
187 name string
188 tty bool
189 color bool
190 result Result
191 action string
192 err error
193 wantStdout string
194 wantStderr string
195 }{
196 {
197 name: "in a terminal, the server's message goes to stderr",
198 tty: true,
199 result: Result{Number: 9},
200 action: "delete artifact 9",
201 err: apiError(404, "Not Found", "9"),
202 wantStderr: "X Failed to delete artifact 9: Not Found\n",
203 },
204 {
205 name: "colors in a terminal",
206 tty: true,
207 color: true,
208 result: Result{Number: 9},
209 action: "delete artifact 9",
210 err: apiError(404, "Not Found", "9"),
211 wantStderr: "\x1b[0;31mX\x1b[0m Failed to delete artifact 9: Not Found\n",
212 },
213 {
214 name: "piped, a failed line goes to stdout",
215 result: Result{Number: 9},
216 action: "delete artifact 9",
217 err: apiError(404, "Not Found", "9"),
218 wantStdout: "failed\t9\t\t\tNot Found\n",
219 },
220 {
221 name: "piped, with the artifact's name",
222 result: Result{Number: 3, Name: "Staging OAuth runbook"},
223 action: "delete artifact 3",
224 err: apiError(403, "Must have admin rights to Repository.", "3"),
225 wantStdout: "failed\t3\tStaging OAuth runbook\t\tMust have admin rights to Repository.\n",
226 },
227 {
228 name: "piped, an artifact without a number leaves its column empty",
229 result: Result{Name: "oauth-research.md", Source: "oauth-research.md"},
230 action: "create artifact from oauth-research.md",
231 err: apiError(503, "Service Unavailable", "7"),
232 wantStdout: "failed\t\toauth-research.md\toauth-research.md\tService Unavailable\n",
233 },

Callers

nothing calls this directly

Calls 10

TestFunction · 0.92
PrintFailureFunction · 0.85
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStderrTTYMethod · 0.80
SetColorEnabledMethod · 0.80
EqualMethod · 0.80
ErrorfMethod · 0.65
RunMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected