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

Function TestHTTPHeaders

api/client_test.go:322–353  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

320}
321
322func 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

Callers

nothing calls this directly

Calls 9

TestFunction · 0.92
NewHTTPClientFunction · 0.85
serverHostnameFunction · 0.85
NewClientFromHTTPFunction · 0.85
EqualMethod · 0.80
CloseMethod · 0.65
RESTMethod · 0.65
GetMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected