MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestCustomHeaderTransportAddsCustomHeaders

Function TestCustomHeaderTransportAddsCustomHeaders

action/command/api_test.go:147–169  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestCustomHeaderTransportAddsCustomHeaders(t *testing.T) {
148 t.Parallel()
149
150 customHeaders := http.Header{}
151 customHeaders.Set("Cookie", "CF_Authorization=token")
152 customHeaders.Set("X-Request-Id", "run-123")
153
154 transport := newCustomHeaderTransport(roundTripFunc(func(req *http.Request) (*http.Response, error) {
155 require.Equal(t, "CF_Authorization=token", req.Header.Get("Cookie"))
156 require.Equal(t, "run-123", req.Header.Get("X-Request-Id"))
157 return &http.Response{
158 StatusCode: http.StatusOK,
159 Header: make(http.Header),
160 Body: io.NopCloser(strings.NewReader("ok")),
161 Request: req,
162 }, nil
163 }), customHeaders)
164
165 resp, err := transport.RoundTrip(httptest.NewRequest(http.MethodGet, "https://example.com", nil))
166 require.NoError(t, err)
167 require.Equal(t, http.StatusOK, resp.StatusCode)
168 require.NoError(t, resp.Body.Close())
169}
170
171func TestCustomHeaderTransportClosesIdleConnections(t *testing.T) {
172 t.Parallel()

Callers

nothing calls this directly

Calls 7

newCustomHeaderTransportFunction · 0.85
roundTripFuncFuncType · 0.85
GetMethod · 0.80
EqualMethod · 0.65
CloseMethod · 0.65
SetMethod · 0.45
RoundTripMethod · 0.45

Tested by

no test coverage detected