mirror of https://github.com/docker/cli.git
restore support for env variables to configure proxy
regression introduced by b34f34 close #39654 Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
aa097cf1aa
commit
e25e077a20
|
@ -6,6 +6,7 @@ import (
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -79,6 +80,24 @@ func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
|
||||||
assert.Check(t, is.Equal(customVersion, apiclient.ClientVersion()))
|
assert.Check(t, is.Equal(customVersion, apiclient.ClientVersion()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewAPIClientFromFlagsWithHttpProxyEnv(t *testing.T) {
|
||||||
|
defer env.Patch(t, "HTTP_PROXY", "http://proxy.acme.com:1234")()
|
||||||
|
defer env.Patch(t, "DOCKER_HOST", "tcp://docker.acme.com:2376")()
|
||||||
|
|
||||||
|
opts := &flags.CommonOptions{}
|
||||||
|
configFile := &configfile.ConfigFile{}
|
||||||
|
apiclient, err := NewAPIClientFromFlags(opts, configFile)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
transport, ok := apiclient.HTTPClient().Transport.(*http.Transport)
|
||||||
|
assert.Assert(t, ok)
|
||||||
|
assert.Assert(t, transport.Proxy != nil)
|
||||||
|
request, err := http.NewRequest(http.MethodGet, "tcp://docker.acme.com:2376", nil)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
url, err := transport.Proxy(request)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Check(t, is.Equal("http://proxy.acme.com:1234", url.String()))
|
||||||
|
}
|
||||||
|
|
||||||
type fakeClient struct {
|
type fakeClient struct {
|
||||||
client.Client
|
client.Client
|
||||||
pingFunc func() (types.Ping, error)
|
pingFunc func() (types.Ping, error)
|
||||||
|
|
|
@ -104,8 +104,8 @@ func (c *Endpoint) ClientOpts() ([]client.Opt, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result = append(result,
|
result = append(result,
|
||||||
client.WithHost(c.Host),
|
|
||||||
withHTTPClient(tlsConfig),
|
withHTTPClient(tlsConfig),
|
||||||
|
client.WithHost(c.Host),
|
||||||
)
|
)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue