TestTCPDynamicProxy tests proxying an unencrypted TCP connection to a TCP upstream server.
(t *testing.T)
| 34 | // TestTCPDynamicProxy tests proxying an unencrypted TCP connection |
| 35 | // to a TCP upstream server. |
| 36 | func TestTCPDyanmicProxy(t *testing.T) { |
| 37 | srv := tcptest.NewServer(echoHandler) |
| 38 | defer srv.Close() |
| 39 | |
| 40 | // start proxy |
| 41 | proxyAddr := "127.0.0.1:57778" |
| 42 | go func() { |
| 43 | h := &tcp.DynamicProxy{ |
| 44 | Lookup: func(h string) *route.Target { |
| 45 | tbl, _ := route.NewTable(bytes.NewBufferString("route add srv 127.0.0.1:57778 tcp://" + srv.Addr)) |
| 46 | return tbl.LookupHost(h, route.Picker["rr"]) |
| 47 | }, |
| 48 | } |
| 49 | l := config.Listen{Addr: proxyAddr} |
| 50 | if err := ListenAndServeTCP(l, h, nil); err != nil { |
| 51 | t.Log("ListenAndServeTCP: ", err) |
| 52 | } |
| 53 | }() |
| 54 | defer Close() |
| 55 | |
| 56 | // connect to proxy |
| 57 | out, err := tcptest.NewRetryDialer().Dial("tcp", proxyAddr) |
| 58 | if err != nil { |
| 59 | t.Fatalf("net.Dial: %#v", err) |
| 60 | } |
| 61 | defer out.Close() |
| 62 | |
| 63 | testRoundtrip(t, out) |
| 64 | } |
| 65 | |
| 66 | // TestTCPProxy tests proxying an unencrypted TCP connection |
| 67 | // to a TCP upstream server. |
nothing calls this directly
no test coverage detected