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

Function TestUploadAuthentication

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

Source from the content-addressed store, hash-verified

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