5
5
package proxy
6
6
7
7
import (
8
+ "context"
8
9
"errors"
9
10
"net"
10
11
"reflect"
@@ -21,10 +22,6 @@ func (r *recordingProxy) Dial(network, addr string) (net.Conn, error) {
21
22
}
22
23
23
24
func TestPerHost (t * testing.T ) {
24
- var def , bypass recordingProxy
25
- perHost := NewPerHost (& def , & bypass )
26
- perHost .AddFromString ("localhost,*.zone,127.0.0.1,10.0.0.1/8,1000::/16" )
27
-
28
25
expectedDef := []string {
29
26
"example.com:123" ,
30
27
"1.2.3.4:123" ,
@@ -39,17 +36,41 @@ func TestPerHost(t *testing.T) {
39
36
"[1000::]:123" ,
40
37
}
41
38
42
- for _ , addr := range expectedDef {
43
- perHost .Dial ("tcp" , addr )
44
- }
45
- for _ , addr := range expectedBypass {
46
- perHost .Dial ("tcp" , addr )
47
- }
39
+ t .Run ("Dial" , func (t * testing.T ) {
40
+ var def , bypass recordingProxy
41
+ perHost := NewPerHost (& def , & bypass )
42
+ perHost .AddFromString ("localhost,*.zone,127.0.0.1,10.0.0.1/8,1000::/16" )
43
+ for _ , addr := range expectedDef {
44
+ perHost .Dial ("tcp" , addr )
45
+ }
46
+ for _ , addr := range expectedBypass {
47
+ perHost .Dial ("tcp" , addr )
48
+ }
48
49
49
- if ! reflect .DeepEqual (expectedDef , def .addrs ) {
50
- t .Errorf ("Hosts which went to the default proxy didn't match. Got %v, want %v" , def .addrs , expectedDef )
51
- }
52
- if ! reflect .DeepEqual (expectedBypass , bypass .addrs ) {
53
- t .Errorf ("Hosts which went to the bypass proxy didn't match. Got %v, want %v" , bypass .addrs , expectedBypass )
54
- }
50
+ if ! reflect .DeepEqual (expectedDef , def .addrs ) {
51
+ t .Errorf ("Hosts which went to the default proxy didn't match. Got %v, want %v" , def .addrs , expectedDef )
52
+ }
53
+ if ! reflect .DeepEqual (expectedBypass , bypass .addrs ) {
54
+ t .Errorf ("Hosts which went to the bypass proxy didn't match. Got %v, want %v" , bypass .addrs , expectedBypass )
55
+ }
56
+ })
57
+
58
+ t .Run ("DialContext" , func (t * testing.T ) {
59
+ var def , bypass recordingProxy
60
+ perHost := NewPerHost (& def , & bypass )
61
+ perHost .AddFromString ("localhost,*.zone,127.0.0.1,10.0.0.1/8,1000::/16" )
62
+ for _ , addr := range expectedDef {
63
+ perHost .DialContext (context .Background (), "tcp" , addr )
64
+ }
65
+ for _ , addr := range expectedBypass {
66
+ perHost .DialContext (context .Background (), "tcp" , addr )
67
+ }
68
+
69
+ if ! reflect .DeepEqual (expectedDef , def .addrs ) {
70
+ t .Errorf ("Hosts which went to the default proxy didn't match. Got %v, want %v" , def .addrs , expectedDef )
71
+ }
72
+ if ! reflect .DeepEqual (expectedBypass , bypass .addrs ) {
73
+ t .Errorf ("Hosts which went to the bypass proxy didn't match. Got %v, want %v" , bypass .addrs , expectedBypass )
74
+ }
75
+ })
55
76
}
0 commit comments