cleanup(netxlite): drop the DefaultDialer legacy name (#796)
Part of https://github.com/ooni/probe/issues/2121
This commit is contained in:
parent
c6b3889a33
commit
07c0b08505
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ooni/probe-cli/v3/internal/model"
|
||||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ const requestWithoutDomainName = `{
|
||||||
func TestWorkingAsIntended(t *testing.T) {
|
func TestWorkingAsIntended(t *testing.T) {
|
||||||
handler := Handler{
|
handler := Handler{
|
||||||
Client: http.DefaultClient,
|
Client: http.DefaultClient,
|
||||||
Dialer: netxlite.DefaultDialer,
|
Dialer: netxlite.NewDialerWithStdlibResolver(model.DiscardLogger),
|
||||||
MaxAcceptableBody: 1 << 24,
|
MaxAcceptableBody: 1 << 24,
|
||||||
Resolver: netxlite.NewResolverSystem(),
|
Resolver: netxlite.NewResolverSystem(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,14 @@ import (
|
||||||
"github.com/ooni/probe-cli/v3/internal/model"
|
"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
|
// NewDialerWithResolver is equivalent to calling WrapDialer with
|
||||||
// the dialer argument being equal to &DialerSystem{}.
|
// the dialer argument being equal to &DialerSystem{}.
|
||||||
func NewDialerWithResolver(dl model.DebugLogger, r model.Resolver, w ...model.DialerWrapper) model.Dialer {
|
func NewDialerWithResolver(dl model.DebugLogger, r model.Resolver, w ...model.DialerWrapper) model.Dialer {
|
||||||
|
|
|
@ -15,6 +15,24 @@ import (
|
||||||
"github.com/ooni/probe-cli/v3/internal/model/mocks"
|
"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 {
|
type extensionDialerFirst struct {
|
||||||
model.Dialer
|
model.Dialer
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ package netxlite
|
||||||
//
|
//
|
||||||
// Deprecated: do not use these names in new code.
|
// Deprecated: do not use these names in new code.
|
||||||
var (
|
var (
|
||||||
DefaultDialer = &DialerSystem{}
|
|
||||||
NewResolverSystem = newResolverSystem
|
NewResolverSystem = newResolverSystem
|
||||||
DefaultResolver = newResolverSystem()
|
DefaultResolver = newResolverSystem()
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,20 +15,24 @@ import (
|
||||||
"github.com/ooni/probe-cli/v3/internal/model/mocks"
|
"github.com/ooni/probe-cli/v3/internal/model/mocks"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewResolverSystem(t *testing.T) {
|
func typecheckForSystemResolver(t *testing.T, resolver model.Resolver, logger model.DebugLogger) {
|
||||||
resolver := NewResolverStdlib(log.Log)
|
|
||||||
idna := resolver.(*resolverIDNA)
|
idna := resolver.(*resolverIDNA)
|
||||||
logger := idna.Resolver.(*resolverLogger)
|
loggerReso := idna.Resolver.(*resolverLogger)
|
||||||
if logger.Logger != log.Log {
|
if loggerReso.Logger != logger {
|
||||||
t.Fatal("invalid logger")
|
t.Fatal("invalid logger")
|
||||||
}
|
}
|
||||||
shortCircuit := logger.Resolver.(*resolverShortCircuitIPAddr)
|
shortCircuit := loggerReso.Resolver.(*resolverShortCircuitIPAddr)
|
||||||
errWrapper := shortCircuit.Resolver.(*resolverErrWrapper)
|
errWrapper := shortCircuit.Resolver.(*resolverErrWrapper)
|
||||||
reso := errWrapper.Resolver.(*resolverSystem)
|
reso := errWrapper.Resolver.(*resolverSystem)
|
||||||
txpErrWrapper := reso.t.(*dnsTransportErrWrapper)
|
txpErrWrapper := reso.t.(*dnsTransportErrWrapper)
|
||||||
_ = txpErrWrapper.DNSTransport.(*dnsOverGetaddrinfoTransport)
|
_ = txpErrWrapper.DNSTransport.(*dnsOverGetaddrinfoTransport)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewResolverSystem(t *testing.T) {
|
||||||
|
resolver := NewResolverStdlib(model.DiscardLogger)
|
||||||
|
typecheckForSystemResolver(t, resolver, model.DiscardLogger)
|
||||||
|
}
|
||||||
|
|
||||||
func TestNewSerialResolverUDP(t *testing.T) {
|
func TestNewSerialResolverUDP(t *testing.T) {
|
||||||
d := NewDialerWithoutResolver(log.Log)
|
d := NewDialerWithoutResolver(log.Log)
|
||||||
resolver := NewSerialResolverUDP(log.Log, d, "1.1.1.1:53")
|
resolver := NewSerialResolverUDP(log.Log, d, "1.1.1.1:53")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user