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

Function TestNewHTTPClientLegacyConfigAttachesToken

api/http_client_test.go:308–332  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

306}
307
308func TestNewHTTPClientLegacyConfigAttachesToken(t *testing.T) {
309 // Regression: HTTPClientOptions.Config (the primitive seam) must keep authenticating requests for external callers.
310 var gotAuthorization string
311 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
312 gotAuthorization = r.Header.Get(authorization)
313 w.WriteHeader(http.StatusNoContent)
314 }))
315 defer ts.Close()
316
317 ios, _, _, _ := iostreams.Test()
318 client, err := NewHTTPClient(HTTPClientOptions{
319 AppVersion: "v1.2.3",
320 Config: legacyConfig{serverHostname(t, ts.URL) + ":oauth_token": "MYTOKEN"},
321 Log: ios.ErrOut,
322 })
323 require.NoError(t, err)
324
325 req, err := http.NewRequest("GET", ts.URL, nil)
326 require.NoError(t, err)
327
328 res, err := client.Do(req)
329 require.NoError(t, err)
330 assert.Equal(t, 204, res.StatusCode)
331 assert.Equal(t, "token MYTOKEN", gotAuthorization)
332}
333
334func TestNewHTTPClientLogHeadlineOnly(t *testing.T) {
335 // Under GH_DEBUG=api the client normally logs a full verbose trace. LogHeadlineOnly must keep it non-verbose, so

Callers

nothing calls this directly

Calls 7

DoMethod · 0.95
TestFunction · 0.92
NewHTTPClientFunction · 0.85
serverHostnameFunction · 0.85
EqualMethod · 0.80
GetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected