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

Function TestNewHTTPClientLogHeadlineOnly

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

Source from the content-addressed store, hash-verified

333}
334
335func TestNewHTTPClientLogHeadlineOnly(t *testing.T) {
336 // Under GH_DEBUG=api the client normally logs a full verbose trace. LogHeadlineOnly must keep it non-verbose, so
337 // only httpretty's head lines are emitted and the request/response header and body lines are suppressed.
338 t.Setenv("GH_DEBUG", "api")
339
340 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
341 w.WriteHeader(http.StatusNoContent)
342 }))
343 defer ts.Close()
344
345 ios, _, _, stderr := iostreams.Test()
346 client, err := NewHTTPClient(HTTPClientOptions{
347 AppVersion: "v1.2.3",
348 Log: ios.ErrOut,
349 LogHeadlineOnly: true,
350 SkipDefaultHeaders: true,
351 })
352 require.NoError(t, err)
353
354 req, err := http.NewRequest("GET", ts.URL, nil)
355 require.NoError(t, err)
356 req.Host = "github.com"
357
358 res, err := client.Do(req)
359 require.NoError(t, err)
360 assert.Equal(t, 204, res.StatusCode)
361
362 assert.Equal(t, heredoc.Doc(`
363 * Request at <time>
364 * Request to http://<host>:<port>
365 * Request took <duration>
366 `), normalizeVerboseLog(stderr.String()))
367}
368
369func TestHTTPClientRedirectAuthenticationHeaderHandling(t *testing.T) {
370 // Two servers stand in for two different hosts. A dial map lets the test

Callers

nothing calls this directly

Calls 7

DoMethod · 0.95
TestFunction · 0.92
NewHTTPClientFunction · 0.85
normalizeVerboseLogFunction · 0.85
EqualMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected