|
|
@@ -5,6 +5,7 @@
|
|
|
package proxy
|
|
|
|
|
|
import (
|
|
|
+ "context"
|
|
|
"errors"
|
|
|
"net"
|
|
|
"reflect"
|
|
|
@@ -21,10 +22,6 @@ func (r *recordingProxy) Dial(network, addr string) (net.Conn, error) {
|
|
|
}
|
|
|
|
|
|
func TestPerHost(t *testing.T) {
|
|
|
- var def, bypass recordingProxy
|
|
|
- perHost := NewPerHost(&def, &bypass)
|
|
|
- perHost.AddFromString("localhost,*.zone,127.0.0.1,10.0.0.1/8,1000::/16")
|
|
|
-
|
|
|
expectedDef := []string{
|
|
|
"example.com:123",
|
|
|
"1.2.3.4:123",
|
|
|
@@ -39,17 +36,41 @@ func TestPerHost(t *testing.T) {
|
|
|
"[1000::]:123",
|
|
|
}
|
|
|
|
|
|
- for _, addr := range expectedDef {
|
|
|
- perHost.Dial("tcp", addr)
|
|
|
- }
|
|
|
- for _, addr := range expectedBypass {
|
|
|
- perHost.Dial("tcp", addr)
|
|
|
- }
|
|
|
+ t.Run("Dial", func(t *testing.T) {
|
|
|
+ var def, bypass recordingProxy
|
|
|
+ perHost := NewPerHost(&def, &bypass)
|
|
|
+ perHost.AddFromString("localhost,*.zone,127.0.0.1,10.0.0.1/8,1000::/16")
|
|
|
+ for _, addr := range expectedDef {
|
|
|
+ perHost.Dial("tcp", addr)
|
|
|
+ }
|
|
|
+ for _, addr := range expectedBypass {
|
|
|
+ perHost.Dial("tcp", addr)
|
|
|
+ }
|
|
|
|
|
|
- if !reflect.DeepEqual(expectedDef, def.addrs) {
|
|
|
- t.Errorf("Hosts which went to the default proxy didn't match. Got %v, want %v", def.addrs, expectedDef)
|
|
|
- }
|
|
|
- if !reflect.DeepEqual(expectedBypass, bypass.addrs) {
|
|
|
- t.Errorf("Hosts which went to the bypass proxy didn't match. Got %v, want %v", bypass.addrs, expectedBypass)
|
|
|
- }
|
|
|
+ if !reflect.DeepEqual(expectedDef, def.addrs) {
|
|
|
+ t.Errorf("Hosts which went to the default proxy didn't match. Got %v, want %v", def.addrs, expectedDef)
|
|
|
+ }
|
|
|
+ if !reflect.DeepEqual(expectedBypass, bypass.addrs) {
|
|
|
+ t.Errorf("Hosts which went to the bypass proxy didn't match. Got %v, want %v", bypass.addrs, expectedBypass)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ t.Run("DialContext", func(t *testing.T) {
|
|
|
+ var def, bypass recordingProxy
|
|
|
+ perHost := NewPerHost(&def, &bypass)
|
|
|
+ perHost.AddFromString("localhost,*.zone,127.0.0.1,10.0.0.1/8,1000::/16")
|
|
|
+ for _, addr := range expectedDef {
|
|
|
+ perHost.DialContext(context.Background(), "tcp", addr)
|
|
|
+ }
|
|
|
+ for _, addr := range expectedBypass {
|
|
|
+ perHost.DialContext(context.Background(), "tcp", addr)
|
|
|
+ }
|
|
|
+
|
|
|
+ if !reflect.DeepEqual(expectedDef, def.addrs) {
|
|
|
+ t.Errorf("Hosts which went to the default proxy didn't match. Got %v, want %v", def.addrs, expectedDef)
|
|
|
+ }
|
|
|
+ if !reflect.DeepEqual(expectedBypass, bypass.addrs) {
|
|
|
+ t.Errorf("Hosts which went to the bypass proxy didn't match. Got %v, want %v", bypass.addrs, expectedBypass)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|