(t *testing.T)
| 306 | } |
| 307 | |
| 308 | func 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 | |
| 334 | func TestNewHTTPClientLogHeadlineOnly(t *testing.T) { |
| 335 | // Under GH_DEBUG=api the client normally logs a full verbose trace. LogHeadlineOnly must keep it non-verbose, so |
nothing calls this directly
no test coverage detected