refactor(netx): move dialer's mockable types in mockablex (#368)

Part of https://github.com/ooni/probe/issues/1591
This commit is contained in:
Simone Basso 2021-06-08 23:59:30 +02:00 committed by GitHub
commit 5b73230a6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 455 additions and 173 deletions

View file

@ -0,0 +1,23 @@
package mockablex
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{}