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

Function TestUpload

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

Source from the content-addressed store, hash-verified

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