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