MCPcopy
hub / github.com/fabiolb/fabio / TestTCPDyanmicProxy

Function TestTCPDyanmicProxy

proxy/tcp_integration_test.go:36–64  ·  view source on GitHub ↗

TestTCPDynamicProxy tests proxying an unencrypted TCP connection to a TCP upstream server.

(t *testing.T)

Source from the content-addressed store, hash-verified

34// TestTCPDynamicProxy tests proxying an unencrypted TCP connection
35// to a TCP upstream server.
36func 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.

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
LookupHostMethod · 0.95
NewServerFunction · 0.92
NewTableFunction · 0.92
NewRetryDialerFunction · 0.92
ListenAndServeTCPFunction · 0.85
CloseFunction · 0.85
testRoundtripFunction · 0.85
LogMethod · 0.65
DialMethod · 0.65

Tested by

no test coverage detected