@@ -107,6 +107,28 @@ func TestParseLocation(t *testing.T) {
107107 assert .Equal (t , "example.com:5000/with/path" , location )
108108}
109109
110+ func TestParseProxy (t * testing.T ) {
111+ for _ , valid := range []string {
112+ "" ,
113+ "http://proxy.example.com" ,
114+ "https://proxy.example.com" ,
115+ "socks5://proxy.example.com" ,
116+ "socks5h://proxy.example.com:1080" ,
117+ } {
118+ _ , err := ParseProxy (valid )
119+ assert .Nil (t , err , valid )
120+ }
121+
122+ for _ , invalid := range []string {
123+ "no-scheme.example.com" ,
124+ "ftp://bad-scheme.example.com" ,
125+ "ssh://bad-scheme.example.com:2222" ,
126+ } {
127+ _ , err := ParseProxy (invalid )
128+ assert .NotNil (t , err )
129+ }
130+ }
131+
110132func TestEmptyConfig (t * testing.T ) {
111133 registries , err := GetRegistries (& types.SystemContext {
112134 SystemRegistriesConfPath : "testdata/empty.conf" ,
@@ -983,3 +1005,31 @@ func TestCredentialHelpers(t *testing.T) {
9831005 require .Equal (t , test .helpers , helpers , "%v" , test )
9841006 }
9851007}
1008+
1009+ func TestProxyConfiguration (t * testing.T ) {
1010+ sys := & types.SystemContext {
1011+ SystemRegistriesConfPath : "testdata/proxy.conf" ,
1012+ SystemRegistriesConfDirPath : "testdata/this-does-not-exist" ,
1013+ }
1014+
1015+ registries , err := GetRegistries (sys )
1016+ require .NoError (t , err )
1017+ require .Equal (t , 2 , len (registries ))
1018+
1019+ reg1 := registries [0 ]
1020+ assert .Equal (t , "registry-1.com" , reg1 .Location )
1021+ assert .Equal (t , "" , reg1 .Proxy )
1022+ require .Equal (t , 2 , len (reg1 .Mirrors ))
1023+
1024+ mirror1 := reg1 .Mirrors [0 ]
1025+ assert .Equal (t , "mirror-1.registry-1.com" , mirror1 .Location )
1026+ assert .Equal (t , "" , mirror1 .Proxy )
1027+
1028+ mirror2 := reg1 .Mirrors [1 ]
1029+ assert .Equal (t , "mirror-2.registry-1.com" , mirror2 .Location )
1030+ assert .Equal (t , "http://proxy-1.example.com" , mirror2 .Proxy )
1031+
1032+ reg2 := registries [1 ]
1033+ assert .Equal (t , "registry-2.com" , reg2 .Location )
1034+ assert .Equal (t , "https://proxy-2.example.com" , reg2 .Proxy )
1035+ }
0 commit comments