refactor(netx): move dialer's mockable types in mockablex (#368)
Part of https://github.com/ooni/probe/issues/1591
This commit is contained in:
parent
b8cae3f5a6
commit
5b73230a6d
14 changed files with 455 additions and 173 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -12,6 +13,7 @@ import (
|
|||
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/transactionid"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex"
|
||||
)
|
||||
|
||||
func TestEmitterFailure(t *testing.T) {
|
||||
|
|
@ -22,7 +24,11 @@ func TestEmitterFailure(t *testing.T) {
|
|||
Handler: saver,
|
||||
})
|
||||
ctx = transactionid.WithTransactionID(ctx)
|
||||
d := dialer.EmitterDialer{Dialer: dialer.EOFDialer{}}
|
||||
d := dialer.EmitterDialer{Dialer: mockablex.Dialer{
|
||||
MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) {
|
||||
return nil, io.EOF
|
||||
},
|
||||
}}
|
||||
conn, err := d.DialContext(ctx, "tcp", "www.google.com:443")
|
||||
if !errors.Is(err, io.EOF) {
|
||||
t.Fatal("not the error we expected")
|
||||
|
|
@ -77,7 +83,24 @@ func TestEmitterSuccess(t *testing.T) {
|
|||
Handler: saver,
|
||||
})
|
||||
ctx = transactionid.WithTransactionID(ctx)
|
||||
d := dialer.EmitterDialer{Dialer: dialer.EOFConnDialer{}}
|
||||
d := dialer.EmitterDialer{Dialer: mockablex.Dialer{
|
||||
MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) {
|
||||
return &mockablex.Conn{
|
||||
MockRead: func(b []byte) (int, error) {
|
||||
return 0, io.EOF
|
||||
},
|
||||
MockWrite: func(b []byte) (int, error) {
|
||||
return 0, io.EOF
|
||||
},
|
||||
MockClose: func() error {
|
||||
return io.EOF
|
||||
},
|
||||
MockLocalAddr: func() net.Addr {
|
||||
return &net.TCPAddr{Port: 12345}
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
}}
|
||||
conn, err := d.DialContext(ctx, "tcp", "www.google.com:443")
|
||||
if err != nil {
|
||||
t.Fatal("we expected no error")
|
||||
|
|
|
|||
Loading…
Reference in a new issue