refactor(netx/dialer): hide implementation complexity (#372)
* refactor(netx/dialer): hide implementation complexity This follows the blueprint of `module.Config` and `nodule.New` described at https://github.com/ooni/probe/issues/1591. * fix: ndt7 bug where we were not using the right resolver * fix(legacy/netx): clarify irrelevant implementation change * fix: improve comments * fix(hhfm): do not use dialer.New b/c it breaks it Unclear to me why this is happening. Still, improve upon the previous situation by adding a timeout. It does not seem a priority to look into this issue now.
This commit is contained in:
parent
b7a6dbe47b
commit
06ee0e55a9
30 changed files with 312 additions and 517 deletions
57
internal/engine/netx/dialer/dialer_test.go
Normal file
57
internal/engine/netx/dialer/dialer_test.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package dialer
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace"
|
||||
)
|
||||
|
||||
func TestNewCreatesTheExpectedChain(t *testing.T) {
|
||||
saver := &trace.Saver{}
|
||||
dlr := New(&Config{
|
||||
ContextByteCounting: true,
|
||||
DialSaver: saver,
|
||||
Logger: log.Log,
|
||||
ProxyURL: &url.URL{},
|
||||
ReadWriteSaver: saver,
|
||||
}, &net.Resolver{})
|
||||
shd, ok := dlr.(*shapingDialer)
|
||||
if !ok {
|
||||
t.Fatal("not a shapingDialer")
|
||||
}
|
||||
bcd, ok := shd.Dialer.(*byteCounterDialer)
|
||||
if !ok {
|
||||
t.Fatal("not a byteCounterDialer")
|
||||
}
|
||||
pd, ok := bcd.Dialer.(*proxyDialer)
|
||||
if !ok {
|
||||
t.Fatal("not a proxyDialer")
|
||||
}
|
||||
dnsd, ok := pd.Dialer.(*dnsDialer)
|
||||
if !ok {
|
||||
t.Fatal("not a dnsDialer")
|
||||
}
|
||||
scd, ok := dnsd.Dialer.(*saverConnDialer)
|
||||
if !ok {
|
||||
t.Fatal("not a saverConnDialer")
|
||||
}
|
||||
sd, ok := scd.Dialer.(*saverDialer)
|
||||
if !ok {
|
||||
t.Fatal("not a saverDialer")
|
||||
}
|
||||
ld, ok := sd.Dialer.(*loggingDialer)
|
||||
if !ok {
|
||||
t.Fatal("not a loggingDialer")
|
||||
}
|
||||
ewd, ok := ld.Dialer.(*errorWrapperDialer)
|
||||
if !ok {
|
||||
t.Fatal("not an errorWrappingDialer")
|
||||
}
|
||||
_, ok = ewd.Dialer.(*net.Dialer)
|
||||
if !ok {
|
||||
t.Fatal("not a net.Dialer")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue