(t *testing.T)
| 320 | } |
| 321 | |
| 322 | func TestHTTPHeaders(t *testing.T) { |
| 323 | var gotReq *http.Request |
| 324 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 325 | gotReq = r |
| 326 | w.WriteHeader(http.StatusNoContent) |
| 327 | })) |
| 328 | defer ts.Close() |
| 329 | |
| 330 | ios, _, _, stderr := iostreams.Test() |
| 331 | httpClient, err := NewHTTPClient(HTTPClientOptions{ |
| 332 | AppVersion: "v1.2.3", |
| 333 | Config: tinyConfig{serverHostname(t, ts.URL) + ":oauth_token": "MYTOKEN"}, |
| 334 | Log: ios.ErrOut, |
| 335 | }) |
| 336 | assert.NoError(t, err) |
| 337 | client := NewClientFromHTTP(httpClient) |
| 338 | |
| 339 | err = client.REST(ts.URL, "GET", ts.URL+"/user/repos", nil, nil) |
| 340 | assert.NoError(t, err) |
| 341 | |
| 342 | wantHeader := map[string]string{ |
| 343 | "Accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview", |
| 344 | "Authorization": "token MYTOKEN", |
| 345 | "Content-Type": "application/json; charset=utf-8", |
| 346 | "User-Agent": "GitHub CLI v1.2.3", |
| 347 | "X-GitHub-Api-Version": "2022-11-28", |
| 348 | } |
| 349 | for name, value := range wantHeader { |
| 350 | assert.Equal(t, value, gotReq.Header.Get(name), name) |
| 351 | } |
| 352 | assert.Equal(t, "", stderr.String()) |
| 353 | } |
| 354 | |
| 355 | // TestWithoutFollowingRedirects verifies that WithoutFollowingRedirects stops the request at the |
| 356 | // redirect and surfaces an HTTPError rather than following through. It also proves the redirect is |
nothing calls this directly
no test coverage detected