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

@ -11,6 +11,7 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter"
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer"
"github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex"
)
func dorequest(ctx context.Context, url string) error {
@ -70,7 +71,11 @@ func TestByteCounterNoHandlers(t *testing.T) {
}
func TestByteCounterConnectFailure(t *testing.T) {
dialer := dialer.ByteCounterDialer{Dialer: dialer.EOFDialer{}}
dialer := dialer.ByteCounterDialer{Dialer: mockablex.Dialer{
MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) {
return nil, io.EOF
},
}}
conn, err := dialer.DialContext(context.Background(), "tcp", "www.google.com:80")
if !errors.Is(err, io.EOF) {
t.Fatal("not the error we expected")