MCPcopy
hub / github.com/caddyserver/caddy / CreateTestingTransport

Function CreateTestingTransport

caddytest/caddytest.go:337–361  ·  view source on GitHub ↗

CreateTestingTransport creates a testing transport that forces call dialing connections to happen locally

()

Source from the content-addressed store, hash-verified

335
336// CreateTestingTransport creates a testing transport that forces call dialing connections to happen locally
337func CreateTestingTransport() *http.Transport {
338 dialer := net.Dialer{
339 Timeout: 5 * time.Second,
340 KeepAlive: 5 * time.Second,
341 DualStack: true,
342 }
343
344 dialContext := func(ctx context.Context, network, addr string) (net.Conn, error) {
345 parts := strings.Split(addr, ":")
346 destAddr := fmt.Sprintf("127.0.0.1:%s", parts[1])
347 log.Printf("caddytest: redirecting the dialer from %s to %s", addr, destAddr)
348 return dialer.DialContext(ctx, network, destAddr)
349 }
350
351 return &http.Transport{
352 Proxy: http.ProxyFromEnvironment,
353 DialContext: dialContext,
354 ForceAttemptHTTP2: true,
355 MaxIdleConns: 100,
356 IdleConnTimeout: 90 * time.Second,
357 TLSHandshakeTimeout: 5 * time.Second,
358 ExpectContinueTimeout: 1 * time.Second,
359 TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec
360 }
361}
362
363// AssertLoadError will load a config and expect an error
364func AssertLoadError(t *testing.T, rawConfig string, configType string, expectedError string) {

Callers 1

NewTesterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected