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

Function TestUpload

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

Source from the content-addressed store, hash-verified

61}
62
63func TestUpload(t *testing.T) {
64 a := testAsset(t, "shot.png", "image/png", "the bytes")
65
66 var gotBody []byte
67 reg := &httpmock.Registry{}
68 defer reg.Verify(t)
69 reg.Register(
70 httpmock.REST("POST", "user-attachments/assets"),
71 func(req *http.Request) (*http.Response, error) {
72 var err error
73 gotBody, err = io.ReadAll(req.Body)
74 require.NoError(t, err)
75 return httpmock.StatusStringResponse(201, `{"url":"https://github.com/user-attachments/assets/be9b3920"}`)(req)
76 },
77 )
78
79 assetURL, err := newTestUploader(t, reg, "github.com", 1234).upload(context.Background(), a)
80
81 require.NoError(t, err)
82 assert.Equal(t, "https://github.com/user-attachments/assets/be9b3920", assetURL)
83 assert.Equal(t, "the bytes", string(gotBody))
84
85 require.Len(t, reg.Requests, 1)
86 req := reg.Requests[0]
87 assert.Equal(t, "POST", req.Method)
88 assert.Equal(t, "https://uploads.github.com/user-attachments/assets?content_type=image%2Fpng&name=shot.png&repository_id=1234", req.URL.String())
89 assert.Equal(t, "application/octet-stream", req.Header.Get("Content-Type"))
90 assert.Equal(t, "application/vnd.github+json", req.Header.Get("Accept"))
91 assert.Equal(t, int64(9), req.ContentLength)
92}
93
94func TestUploadHostForTenant(t *testing.T) {
95 a := testAsset(t, "shot.png", "image/png", "x")

Callers

nothing calls this directly

Calls 11

VerifyMethod · 0.95
RegisterMethod · 0.95
RESTFunction · 0.92
StatusStringResponseFunction · 0.92
testAssetFunction · 0.85
newTestUploaderFunction · 0.85
uploadMethod · 0.80
EqualMethod · 0.80
LenMethod · 0.65
StringMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected