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

Function TestUploadErrors

internal/attachments/client_test.go:165–351  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

163}
164
165func 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 {

Callers

nothing calls this directly

Calls 14

VerifyMethod · 0.95
RegisterMethod · 0.95
StatusJSONResponseFunction · 0.92
StatusStringResponseFunction · 0.92
RESTFunction · 0.92
testAssetFunction · 0.85
newTestUploaderFunction · 0.85
uploadMethod · 0.80
ContainsMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected