44 "fmt"
55 "io/ioutil"
66 "os"
7+ "sort"
78 "testing"
89
910 "github.com/docker/cli/cli/config/credentials"
@@ -28,30 +29,31 @@ func TestProxyConfig(t *testing.T) {
2829 httpsProxy := "https://user:[email protected] :3129" 2930 ftpProxy := "http://ftpproxy.mycorp.com:21"
3031 noProxy := "*.intra.mycorp.com"
31- defaultProxyConfig := ProxyConfig {
32- HTTPProxy : httpProxy ,
33- HTTPSProxy : httpsProxy ,
34- FTPProxy : ftpProxy ,
35- NoProxy : noProxy ,
36- }
3732
3833 cfg := ConfigFile {
3934 Proxies : map [string ]ProxyConfig {
40- "default" : defaultProxyConfig ,
35+ "default" : {
36+ HTTPProxy : httpProxy ,
37+ HTTPSProxy : httpsProxy ,
38+ FTPProxy : ftpProxy ,
39+ NoProxy : noProxy ,
40+ },
4141 },
4242 }
4343
4444 proxyConfig := cfg .ParseProxyConfig ("/var/run/docker.sock" , []string {})
45- expected := map [ string ] * string {
46- "HTTP_PROXY" : & httpProxy ,
47- "http_proxy" : & httpProxy ,
48- "HTTPS_PROXY" : & httpsProxy ,
49- "https_proxy" : & httpsProxy ,
50- "FTP_PROXY" : & ftpProxy ,
51- "ftp_proxy" : & ftpProxy ,
52- "NO_PROXY" : & noProxy ,
53- "no_proxy" : & noProxy ,
45+ expected := [] string {
46+ "HTTP_PROXY=" + httpProxy ,
47+ "http_proxy=" + httpProxy ,
48+ "HTTPS_PROXY=" + httpsProxy ,
49+ "https_proxy=" + httpsProxy ,
50+ "FTP_PROXY=" + ftpProxy ,
51+ "ftp_proxy=" + ftpProxy ,
52+ "NO_PROXY=" + noProxy ,
53+ "no_proxy=" + noProxy ,
5454 }
55+ sort .Strings (proxyConfig )
56+ sort .Strings (expected )
5557 assert .Check (t , is .DeepEqual (expected , proxyConfig ))
5658}
5759
@@ -62,16 +64,15 @@ func TestProxyConfigOverride(t *testing.T) {
6264 httpsProxy := "https://user:[email protected] :3129" 6365 ftpProxy := "http://ftpproxy.mycorp.com:21"
6466 noProxy := "*.intra.mycorp.com"
65- defaultProxyConfig := ProxyConfig {
66- HTTPProxy : httpProxy ,
67- HTTPSProxy : httpsProxy ,
68- FTPProxy : ftpProxy ,
69- NoProxy : noProxy ,
70- }
7167
7268 cfg := ConfigFile {
7369 Proxies : map [string ]ProxyConfig {
74- "default" : defaultProxyConfig ,
70+ "default" : {
71+ HTTPProxy : httpProxy ,
72+ HTTPSProxy : httpsProxy ,
73+ FTPProxy : ftpProxy ,
74+ NoProxy : noProxy ,
75+ },
7576 },
7677 }
7778
@@ -104,23 +105,20 @@ func TestProxyConfigPerHost(t *testing.T) {
104105 extFTPProxy := "http://ftpproxy.example.com:21"
105106 extNoProxy := "*.intra.example.com"
106107
107- defaultProxyConfig := ProxyConfig {
108- HTTPProxy : httpProxy ,
109- HTTPSProxy : httpsProxy ,
110- FTPProxy : ftpProxy ,
111- NoProxy : noProxy ,
112- }
113- externalProxyConfig := ProxyConfig {
114- HTTPProxy : extHTTPProxy ,
115- HTTPSProxy : extHTTPSProxy ,
116- FTPProxy : extFTPProxy ,
117- NoProxy : extNoProxy ,
118- }
119-
120108 cfg := ConfigFile {
121109 Proxies : map [string ]ProxyConfig {
122- "default" : defaultProxyConfig ,
123- "tcp://example.docker.com:2376" : externalProxyConfig ,
110+ "default" : {
111+ HTTPProxy : httpProxy ,
112+ HTTPSProxy : httpsProxy ,
113+ FTPProxy : ftpProxy ,
114+ NoProxy : noProxy ,
115+ },
116+ "tcp://example.docker.com:2376" : {
117+ HTTPProxy : extHTTPProxy ,
118+ HTTPSProxy : extHTTPSProxy ,
119+ FTPProxy : extFTPProxy ,
120+ NoProxy : extNoProxy ,
121+ },
124122 },
125123 }
126124
0 commit comments