ooni-probe-cli/internal/netxmocks/dialer.go
Simone Basso c5dd9a68f1
feat(netxmocks): implement mocks for netxlite.Resolver (#398)
While there, make sure we require using &netxmocks.Dialer.

Still part of https://github.com/ooni/probe/issues/1505
2021-06-23 16:21:13 +02:00

24 lines
564 B
Go

package netxmocks
import (
"context"
"net"
)
// dialer is the interface we expect from a dialer
type dialer interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
// Dialer is a mockable Dialer.
type Dialer struct {
MockDialContext func(ctx context.Context, network, address string) (net.Conn, error)
}
// DialContext implements Dialer.DialContext.
func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
return d.MockDialContext(ctx, network, address)
}
var _ dialer = &Dialer{}