(t *testing.T)
| 163 | } |
| 164 | |
| 165 | func TestUploadErrors(t *testing.T) { |
| 166 | tests := []struct { |
| 167 | name string |
| 168 | file string |
| 169 | contentType string |
| 170 | status int |
| 171 | response string |
| 172 | retryAfter string |
| 173 | // nonJSON sends response bytes verbatim instead of marshaling them as |
| 174 | // json.RawMessage. The "unreadable response" row uses it so the decoder |
| 175 | // receives invalid JSON rather than an empty body from a failed marshal. |
| 176 | nonJSON bool |
| 177 | wantErr string |
| 178 | wantErrPrefix string |
| 179 | wantStatusCode int |
| 180 | }{ |
| 181 | { |
| 182 | name: "no write access", |
| 183 | file: "login.png", |
| 184 | contentType: "image/png", |
| 185 | status: 404, |
| 186 | response: `{"message":"Not Found"}`, |
| 187 | wantErr: "could not upload ./login.png: attaching files requires write access to the repository", |
| 188 | wantStatusCode: 404, |
| 189 | }, |
| 190 | { |
| 191 | // The server's limit for a video depends on an account plan gh |
| 192 | // cannot see, so its own words are what a user can act on. |
| 193 | name: "rejected as too large", |
| 194 | file: "clip.mp4", |
| 195 | contentType: "video/mp4", |
| 196 | status: 413, |
| 197 | response: `{"message":"Payload Too Large"}`, |
| 198 | wantErrPrefix: "failed to upload ./clip.mp4: HTTP 413: Payload Too Large", |
| 199 | wantStatusCode: 413, |
| 200 | }, |
| 201 | { |
| 202 | name: "rejected with one stated cause", |
| 203 | file: "clip.mp4", |
| 204 | contentType: "video/mp4", |
| 205 | status: 422, |
| 206 | response: `{"message":"Validation Failed","errors":[ |
| 207 | {"field":"content_type","message":"content_type is not included in the list of allowed content types"}]}`, |
| 208 | wantErr: "could not upload ./clip.mp4: Validation Failed; content_type is not included in the list of allowed content types", |
| 209 | wantStatusCode: 422, |
| 210 | }, |
| 211 | { |
| 212 | name: "rejected with several stated causes", |
| 213 | file: "shot.png", |
| 214 | contentType: "image/png", |
| 215 | status: 422, |
| 216 | response: `{"message":"Validation Failed","errors":[ |
| 217 | {"field":"content_type","message":"content_type is not included in the list of allowed content types"}, |
| 218 | {"field":"name","message":"name has a file extension that does not match the content type"}]}`, |
| 219 | wantErr: "could not upload ./shot.png: Validation Failed; content_type is not included in the list of allowed content types; name has a file extension that does not match the content type", |
| 220 | wantStatusCode: 422, |
| 221 | }, |
| 222 | { |
nothing calls this directly
no test coverage detected