github.com/nyarla/net-paranoid-go@v0.0.0-20220128023827-1f72d4cf809c/dialer_test.go (about) 1 package paranoid 2 3 import ( 4 "context" 5 "net" 6 "sync" 7 "testing" 8 "time" 9 ) 10 11 func TestParanoidDialer(t *testing.T) { 12 parent := new(net.Dialer) 13 ctx, cancel := context.WithTimeout(context.Background(), time.Minute) 14 15 ip := NewBlockIPRules(IsBlockRecommended) 16 host := NewAllowHostRules(StringHostMatcher(`the.kalaclista.com`, IsSameHost)) 17 18 defer cancel() 19 20 dialer := NewDialer(parent, ip, host) 21 22 if _, err := dialer.DialContext(ctx, `tcp`, `the.kalaclista.com:443`); err != nil { 23 t.Errorf(`failed to test for ParanodDialer: %v`, err) 24 } 25 } 26 27 func BenchmarkParanoidDialer(b *testing.B) { 28 parent := new(net.Dialer) 29 ctx, cancel := context.WithTimeout(context.Background(), time.Minute) 30 31 ip := NewBlockIPRules(IsBlockRecommended) 32 host := NewAllowHostRules(StringHostMatcher(`the.kalaclista.com`, IsSameHost)) 33 34 defer cancel() 35 var once sync.Once 36 37 dialer := NewDialer(parent, ip, host) 38 39 b.ReportAllocs() 40 once.Do(func() { 41 dialer.DialContext(ctx, `tcp`, `the.kalaclista.com:443`) 42 }) 43 }