MCPcopy
hub / github.com/moby/moby / testProxyAt

Function testProxyAt

cmd/docker-proxy/network_proxy_linux_test.go:218–256  ·  view source on GitHub ↗
(t *testing.T, proto string, proxy Proxy, addr string, halfClose bool)

Source from the content-addressed store, hash-verified

216}
217
218func testProxyAt(t *testing.T, proto string, proxy Proxy, addr string, halfClose bool) {
219 t.Helper()
220 defer proxy.Close()
221 go proxy.Run()
222 var client net.Conn
223 var err error
224 if strings.HasPrefix(proto, "sctp") {
225 var a *sctp.SCTPAddr
226 a, err = sctp.ResolveSCTPAddr(proto, addr)
227 if err != nil {
228 t.Fatal(err)
229 }
230 client, err = sctp.DialSCTP(proto, nil, a)
231 } else {
232 client, err = net.Dial(proto, addr)
233 }
234
235 if err != nil {
236 t.Fatalf("Can't connect to the proxy: %v", err)
237 }
238 defer client.Close()
239 client.SetDeadline(time.Now().Add(10 * time.Second))
240 if _, err = client.Write(testBuf); err != nil {
241 t.Fatal(err)
242 }
243 if halfClose {
244 if proto != "tcp" {
245 t.Fatalf("halfClose is not supported for %s", proto)
246 }
247 client.(*net.TCPConn).CloseWrite()
248 }
249 recvBuf := make([]byte, testBufSize)
250 if _, err = client.Read(recvBuf); err != nil {
251 t.Fatal(err)
252 }
253 if !bytes.Equal(testBuf, recvBuf) {
254 t.Fatal(fmt.Errorf("Expected [%v] but got [%v]", testBuf, recvBuf))
255 }
256}
257
258func testTCP4Proxy(t *testing.T, halfClose bool, hostPort int) {
259 t.Helper()

Callers 9

testTCP4ProxyFunction · 0.85
TestTCP6ProxyFunction · 0.85
TestTCPDualStackProxyFunction · 0.85
testUDP4ProxyFunction · 0.85
TestUDP6ProxyFunction · 0.85
TestSCTP4ProxyNoListenerFunction · 0.85
TestSCTP6ProxyNoListenerFunction · 0.85
TestSCTP4ProxyFunction · 0.85
TestSCTP6ProxyFunction · 0.85

Calls 9

EqualMethod · 0.80
ErrorfMethod · 0.80
HelperMethod · 0.65
CloseMethod · 0.65
RunMethod · 0.65
AddMethod · 0.65
CloseWriteMethod · 0.65
WriteMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…