github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/libkb/proxy_test.go (about) 1 package libkb 2 3 import ( 4 "net/url" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestProxyTypeStrToEnum(t *testing.T) { 11 proxyType, ok := ProxyTypeStrToEnum["socks"] 12 require.Equal(t, Socks, proxyType) 13 require.Equal(t, true, ok) 14 15 proxyType, ok = ProxyTypeStrToEnum["http_connect"] 16 require.Equal(t, HTTPConnect, proxyType) 17 require.Equal(t, true, ok) 18 19 _, ok = ProxyTypeStrToEnum["bogus"] 20 require.Equal(t, false, ok) 21 } 22 23 func TestMakeProxy(t *testing.T) { 24 resetGlobals() 25 mockedEnv := NewEnv(MockedConfigReader{}, MockedConfigReader{}, makeLogGetter(t)) 26 27 require.Equal(t, NoProxy, mockedEnv.GetProxyType()) 28 require.Equal(t, "", mockedEnv.GetProxy()) 29 f := MakeProxy(mockedEnv) 30 retURL, err := f(nil) 31 32 // A nil retURL means no proxy 33 require.Equal(t, (*url.URL)(nil), retURL) 34 require.Equal(t, nil, err) 35 36 globalProxyType = "Socks" 37 require.Equal(t, Socks, mockedEnv.GetProxyType()) 38 globalProxyAddress = "localhost:8090" 39 require.Equal(t, "localhost:8090", mockedEnv.GetProxy()) 40 f = MakeProxy(mockedEnv) 41 retURL, err = f(nil) 42 require.Equal(t, nil, err) 43 require.Equal(t, "socks5://localhost:8090", retURL.String()) 44 45 globalProxyType = "http_connect" 46 require.Equal(t, HTTPConnect, mockedEnv.GetProxyType()) 47 f = MakeProxy(mockedEnv) 48 retURL, err = f(nil) 49 require.Equal(t, nil, err) 50 require.Equal(t, "http://localhost:8090", retURL.String()) 51 }