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

Function TestUploadErrors

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

Source from the content-addressed store, hash-verified

159}
160
161func 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 {

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