refactor(netxlite): add more functions to resolver (#455)
We would like to refactor the code so that a DoH resolver owns the connections of its underlying HTTP client. To do that, we need first to incorporate CloseIdleConnections into the Resolver model. Then, we need to add the same function to all netxlite types that wrap a Resolver type. At the same time, we want the rest of the code for now to continue with the simpler definition of a Resolver, now called ResolverLegacy. We will eventually propagate this change to the rest of the tree and simplify the way in which we manage Resolvers. To make this possible, we introduce a new factory function that adapts a ResolverLegacy to become a Resolver. See https://github.com/ooni/probe/issues/1591.
This commit is contained in:
parent
2e0118d1a6
commit
a3654f60b7
22 changed files with 278 additions and 118 deletions
|
|
@ -3,7 +3,6 @@ package netxlite
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
|
@ -71,26 +70,6 @@ func TestResolverLoggerWithFailure(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestResolverLoggerChildNetworkAddress(t *testing.T) {
|
||||
r := &resolverLogger{Logger: log.Log, Resolver: DefaultResolver}
|
||||
if r.Network() != "system" {
|
||||
t.Fatal("invalid Network")
|
||||
}
|
||||
if r.Address() != "" {
|
||||
t.Fatal("invalid Address")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolverLoggerNoChildNetworkAddress(t *testing.T) {
|
||||
r := &resolverLogger{Logger: log.Log, Resolver: &net.Resolver{}}
|
||||
if r.Network() != "logger" {
|
||||
t.Fatal("invalid Network")
|
||||
}
|
||||
if r.Address() != "" {
|
||||
t.Fatal("invalid Address")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolverIDNAWorksAsIntended(t *testing.T) {
|
||||
expectedIPs := []string{"77.88.55.66"}
|
||||
r := &resolverIDNA{
|
||||
|
|
@ -130,24 +109,22 @@ func TestResolverIDNAWithInvalidPunycode(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestResolverIDNAChildNetworkAddress(t *testing.T) {
|
||||
r := &resolverIDNA{
|
||||
Resolver: DefaultResolver,
|
||||
func TestNewResolverTypeChain(t *testing.T) {
|
||||
r := NewResolver(&ResolverConfig{
|
||||
Logger: log.Log,
|
||||
})
|
||||
ridna, ok := r.(*resolverIDNA)
|
||||
if !ok {
|
||||
t.Fatal("invalid resolver")
|
||||
}
|
||||
if v := r.Network(); v != "system" {
|
||||
t.Fatal("invalid network", v)
|
||||
rl, ok := ridna.Resolver.(*resolverLogger)
|
||||
if !ok {
|
||||
t.Fatal("invalid resolver")
|
||||
}
|
||||
if v := r.Address(); v != "" {
|
||||
t.Fatal("invalid address", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolverIDNANoChildNetworkAddress(t *testing.T) {
|
||||
r := &resolverIDNA{}
|
||||
if v := r.Network(); v != "idna" {
|
||||
t.Fatal("invalid network", v)
|
||||
}
|
||||
if v := r.Address(); v != "" {
|
||||
t.Fatal("invalid address", v)
|
||||
if rl.Logger != log.Log {
|
||||
t.Fatal("invalid logger")
|
||||
}
|
||||
if _, ok := rl.Resolver.(*resolverSystem); !ok {
|
||||
t.Fatal("invalid resolver")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue