|
| 1 | +package ocireg |
| 2 | + |
| 3 | +import ( |
| 4 | + "crypto/tls" |
| 5 | + "net/http" |
| 6 | + "reflect" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | + "github.com/stretchr/testify/require" |
| 11 | +) |
| 12 | + |
| 13 | +func TestNewHTTPTransportClonesDefaultTransport(t *testing.T) { |
| 14 | + t.Parallel() |
| 15 | + |
| 16 | + base, ok := http.DefaultTransport.(*http.Transport) |
| 17 | + require.True(t, ok, "default transport must be *http.Transport") |
| 18 | + |
| 19 | + conf := &tls.Config{MinVersion: tls.VersionTLS12} |
| 20 | + |
| 21 | + got := newHTTPTransport(conf) |
| 22 | + require.NotNil(t, got) |
| 23 | + |
| 24 | + assert.NotSame(t, base, got) |
| 25 | + assert.Same(t, conf, got.TLSClientConfig) |
| 26 | + assert.Equal(t, base.ForceAttemptHTTP2, got.ForceAttemptHTTP2) |
| 27 | + assert.Equal(t, base.MaxIdleConns, got.MaxIdleConns) |
| 28 | + assert.Equal(t, base.MaxIdleConnsPerHost, got.MaxIdleConnsPerHost) |
| 29 | + assert.Equal(t, base.MaxConnsPerHost, got.MaxConnsPerHost) |
| 30 | + assert.Equal(t, base.IdleConnTimeout, got.IdleConnTimeout) |
| 31 | + assert.Equal(t, base.TLSHandshakeTimeout, got.TLSHandshakeTimeout) |
| 32 | + assert.Equal(t, base.ExpectContinueTimeout, got.ExpectContinueTimeout) |
| 33 | + |
| 34 | + if base.Proxy != nil { |
| 35 | + require.NotNil(t, got.Proxy) |
| 36 | + assert.Equal(t, reflect.ValueOf(base.Proxy).Pointer(), reflect.ValueOf(got.Proxy).Pointer()) |
| 37 | + } |
| 38 | +} |
0 commit comments