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

Function TestNewHTTPClientLogHeadlineOnly

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

Source from the content-addressed store, hash-verified

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
336 // only httpretty's head lines are emitted and the request/response header and body lines are suppressed.
337 t.Setenv("GH_DEBUG", "api")
338
339 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
340 w.WriteHeader(http.StatusNoContent)
341 }))
342 defer ts.Close()
343
344 ios, _, _, stderr := iostreams.Test()
345 client, err := NewHTTPClient(HTTPClientOptions{
346 AppVersion: "v1.2.3",
347 Log: ios.ErrOut,
348 LogHeadlineOnly: true,
349 SkipDefaultHeaders: true,
350 })
351 require.NoError(t, err)
352
353 req, err := http.NewRequest("GET", ts.URL, nil)
354 require.NoError(t, err)
355 req.Host = "github.com"
356
357 res, err := client.Do(req)
358 require.NoError(t, err)
359 assert.Equal(t, 204, res.StatusCode)
360
361 assert.Equal(t, heredoc.Doc(`
362 * Request at <time>
363 * Request to http://<host>:<port>
364 * Request took <duration>
365 `), normalizeVerboseLog(stderr.String()))
366}
367
368func TestHTTPClientRedirectAuthenticationHeaderHandling(t *testing.T) {
369 // 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