cleanup(netxlite): drop the DefaultDialer legacy name (#796)

Part of https://github.com/ooni/probe/issues/2121
This commit is contained in:
Simone Basso 2022-06-05 18:44:17 +02:00 committed by GitHub
parent c6b3889a33
commit 07c0b08505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 7 deletions

View File

@ -9,6 +9,7 @@ import (
"strings"
"testing"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@ -51,7 +52,7 @@ const requestWithoutDomainName = `{
func TestWorkingAsIntended(t *testing.T) {
handler := Handler{
Client: http.DefaultClient,
Dialer: netxlite.DefaultDialer,
Dialer: netxlite.NewDialerWithStdlibResolver(model.DiscardLogger),
MaxAcceptableBody: 1 << 24,
Resolver: netxlite.NewResolverSystem(),
}

View File

@ -14,6 +14,14 @@ import (
"github.com/ooni/probe-cli/v3/internal/model"
)
// NewDialerWithStdlibResolver is equivalent to creating a system resolver
// using NewResolverStdlib and then a dialer using NewDialerWithResolver where
// the resolver argument is the previously created resolver.
func NewDialerWithStdlibResolver(dl model.DebugLogger) model.Dialer {
reso := NewResolverStdlib(dl)
return NewDialerWithResolver(dl, reso)
}
// NewDialerWithResolver is equivalent to calling WrapDialer with
// the dialer argument being equal to &DialerSystem{}.
func NewDialerWithResolver(dl model.DebugLogger, r model.Resolver, w ...model.DialerWrapper) model.Dialer {

View File

@ -15,6 +15,24 @@ import (
"github.com/ooni/probe-cli/v3/internal/model/mocks"
)
func TestNewDialerWithStdlibResolver(t *testing.T) {
dialer := NewDialerWithStdlibResolver(model.DiscardLogger)
logger := dialer.(*dialerLogger)
if logger.DebugLogger != model.DiscardLogger {
t.Fatal("invalid logger")
}
// typecheck the resolver
reso := logger.Dialer.(*dialerResolver)
typecheckForSystemResolver(t, reso.Resolver, model.DiscardLogger)
// typecheck the dialer
logger = reso.Dialer.(*dialerLogger)
if logger.DebugLogger != model.DiscardLogger {
t.Fatal("invalid logger")
}
errWrapper := logger.Dialer.(*dialerErrWrapper)
_ = errWrapper.Dialer.(*DialerSystem)
}
type extensionDialerFirst struct {
model.Dialer
}

View File

@ -8,7 +8,6 @@ package netxlite
//
// Deprecated: do not use these names in new code.
var (
DefaultDialer = &DialerSystem{}
NewResolverSystem = newResolverSystem
DefaultResolver = newResolverSystem()
)

View File

@ -15,20 +15,24 @@ import (
"github.com/ooni/probe-cli/v3/internal/model/mocks"
)
func TestNewResolverSystem(t *testing.T) {
resolver := NewResolverStdlib(log.Log)
func typecheckForSystemResolver(t *testing.T, resolver model.Resolver, logger model.DebugLogger) {
idna := resolver.(*resolverIDNA)
logger := idna.Resolver.(*resolverLogger)
if logger.Logger != log.Log {
loggerReso := idna.Resolver.(*resolverLogger)
if loggerReso.Logger != logger {
t.Fatal("invalid logger")
}
shortCircuit := logger.Resolver.(*resolverShortCircuitIPAddr)
shortCircuit := loggerReso.Resolver.(*resolverShortCircuitIPAddr)
errWrapper := shortCircuit.Resolver.(*resolverErrWrapper)
reso := errWrapper.Resolver.(*resolverSystem)
txpErrWrapper := reso.t.(*dnsTransportErrWrapper)
_ = txpErrWrapper.DNSTransport.(*dnsOverGetaddrinfoTransport)
}
func TestNewResolverSystem(t *testing.T) {
resolver := NewResolverStdlib(model.DiscardLogger)
typecheckForSystemResolver(t, resolver, model.DiscardLogger)
}
func TestNewSerialResolverUDP(t *testing.T) {
d := NewDialerWithoutResolver(log.Log)
resolver := NewSerialResolverUDP(log.Log, d, "1.1.1.1:53")