aa77867145
This quirk really saddens me. It's a piece of tech debt we're carrying over from the original netx implementation. We cannot remove it _until_ we have legacy netx code around. The second best thing we can do is to clearly move this code in a place where it's clear it's a quirk and write and use some extra code that makes sure the quirk's assumptions are always met. Sigh. See https://github.com/ooni/probe/issues/1591
63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package netxlite
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite/mocks"
|
|
)
|
|
|
|
func TestResolverLegacyAdapterWithCompatibleType(t *testing.T) {
|
|
var called bool
|
|
r := NewResolverLegacyAdapter(&mocks.Resolver{
|
|
MockNetwork: func() string {
|
|
return "network"
|
|
},
|
|
MockAddress: func() string {
|
|
return "address"
|
|
},
|
|
MockCloseIdleConnections: func() {
|
|
called = true
|
|
},
|
|
})
|
|
if r.Network() != "network" {
|
|
t.Fatal("invalid Network")
|
|
}
|
|
if r.Address() != "address" {
|
|
t.Fatal("invalid Address")
|
|
}
|
|
r.CloseIdleConnections()
|
|
if !called {
|
|
t.Fatal("not called")
|
|
}
|
|
}
|
|
|
|
func TestResolverLegacyAdapterDefaults(t *testing.T) {
|
|
r := NewResolverLegacyAdapter(&net.Resolver{})
|
|
if r.Network() != "adapter" {
|
|
t.Fatal("invalid Network")
|
|
}
|
|
if r.Address() != "" {
|
|
t.Fatal("invalid Address")
|
|
}
|
|
r.CloseIdleConnections() // does not crash
|
|
}
|
|
|
|
func TestDialerLegacyAdapterWithCompatibleType(t *testing.T) {
|
|
var called bool
|
|
r := NewDialerLegacyAdapter(&mocks.Dialer{
|
|
MockCloseIdleConnections: func() {
|
|
called = true
|
|
},
|
|
})
|
|
r.CloseIdleConnections()
|
|
if !called {
|
|
t.Fatal("not called")
|
|
}
|
|
}
|
|
|
|
func TestDialerLegacyAdapterDefaults(t *testing.T) {
|
|
r := NewDialerLegacyAdapter(&net.Dialer{})
|
|
r.CloseIdleConnections() // does not crash
|
|
}
|