(t *testing.T, proto string, proxy Proxy, addr string, halfClose bool)
| 216 | } |
| 217 | |
| 218 | func 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 | |
| 258 | func testTCP4Proxy(t *testing.T, halfClose bool, hostPort int) { |
| 259 | t.Helper() |
no test coverage detected
searching dependent graphs…