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

Function TestUploadAuthentication

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

Source from the content-addressed store, hash-verified

109}
110
111func TestUploadAuthentication(t *testing.T) {
112 tests := []struct {
113 name string
114 configuredHost string
115 configuredToken string
116 wantRequestHost string
117 wantAuthorization string
118 }{
119 {
120 name: "GitHub upload host uses github.com token",
121 configuredHost: "github.com",
122 configuredToken: "github-token",
123 wantRequestHost: "uploads.github.com",
124 wantAuthorization: "token github-token",
125 },
126 {
127 name: "tenant upload host uses tenant token",
128 configuredHost: "acme.ghe.com",
129 configuredToken: "tenant-token",
130 wantRequestHost: "uploads.acme.ghe.com",
131 wantAuthorization: "token tenant-token",
132 },
133 }
134
135 for _, tt := range tests {
136 t.Run(tt.name, func(t *testing.T) {
137 a := testAsset(t, "shot.png", "image/png", "x")
138
139 reg := &httpmock.Registry{}
140 defer reg.Verify(t)
141 reg.Register(
142 httpmock.REST("POST", "user-attachments/assets"),
143 httpmock.StatusStringResponse(201, `{"url":"https://github.com/user-attachments/assets/1"}`),
144 )
145
146 client := &http.Client{
147 Transport: api.AddAuthTokenHeader(
148 reg,
149 staticTokenConfig{tt.configuredHost: tt.configuredToken},
150 ),
151 }
152 uploader, err := NewUploader(client, gh.TokenTypeOAuth, tt.configuredHost, 1, "WRITE")
153 require.NoError(t, err)
154
155 _, err = uploader.upload(context.Background(), a)
156
157 require.NoError(t, err)
158 require.Len(t, reg.Requests, 1)
159 assert.Equal(t, tt.wantRequestHost, reg.Requests[0].URL.Host)
160 assert.Equal(t, tt.wantAuthorization, reg.Requests[0].Header.Get("Authorization"))
161 })
162 }
163}
164
165func TestUploadErrors(t *testing.T) {
166 tests := []struct {

Callers

nothing calls this directly

Calls 12

VerifyMethod · 0.95
RegisterMethod · 0.95
uploadMethod · 0.95
RESTFunction · 0.92
StatusStringResponseFunction · 0.92
AddAuthTokenHeaderFunction · 0.92
testAssetFunction · 0.85
NewUploaderFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
LenMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected