feat(netxlite): add dialer factory, simplify resolver factory (#459)

See https://github.com/ooni/probe/issues/1591
This commit is contained in:
Simone Basso 2021-09-05 20:41:46 +02:00 committed by GitHub
commit 6a1e92cace
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 107 additions and 19 deletions

View file

@ -180,9 +180,7 @@ func TestResolverIDNAWithInvalidPunycode(t *testing.T) {
}
func TestNewResolverTypeChain(t *testing.T) {
r := NewResolver(&ResolverConfig{
Logger: log.Log,
})
r := NewResolverSystem(log.Log)
ridna, ok := r.(*resolverIDNA)
if !ok {
t.Fatal("invalid resolver")
@ -238,3 +236,22 @@ func TestResolverShortCircuitIPAddrWithDomain(t *testing.T) {
t.Fatal("invalid result")
}
}
func TestNullResolverWorksAsIntended(t *testing.T) {
r := &nullResolver{}
ctx := context.Background()
addrs, err := r.LookupHost(ctx, "dns.google")
if !errors.Is(err, ErrNoResolver) {
t.Fatal("not the error we expected", err)
}
if addrs != nil {
t.Fatal("expected nil addr")
}
if r.Network() != "null" {
t.Fatal("invalid network")
}
if r.Address() != "" {
t.Fatal("invalid address")
}
r.CloseIdleConnections() // should not crash
}