(t *testing.T)
| 174 | } |
| 175 | |
| 176 | func 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 | }, |
nothing calls this directly
no test coverage detected