From 16aa8e5538381c3243c75d2a9514893cbd3c95d9 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Wed, 23 Jun 2021 16:06:02 +0200 Subject: [PATCH] refactor: rename i/e/n/mockablex => i/netxmocks (#397) Needed to more easily do https://github.com/ooni/probe/issues/1505 --- internal/bytecounter/conn_test.go | 6 +++--- internal/engine/legacy/netx/emitterdialer_test.go | 8 ++++---- internal/engine/netx/dialer/bytecounter_test.go | 4 ++-- internal/engine/netx/dialer/errorwrapper_test.go | 8 ++++---- internal/engine/netx/dialer/proxy_test.go | 6 +++--- internal/engine/netx/dialer/saver_test.go | 10 +++++----- internal/engine/netx/mockablex/doc.go | 2 -- internal/netxlite/dialer_test.go | 12 ++++++------ .../{engine/netx/mockablex => netxmocks}/conn.go | 2 +- .../netx/mockablex => netxmocks}/conn_test.go | 2 +- .../{engine/netx/mockablex => netxmocks}/dialer.go | 2 +- .../netx/mockablex => netxmocks}/dialer_test.go | 2 +- internal/netxmocks/doc.go | 2 ++ internal/ptx/obfs4_test.go | 8 ++++---- internal/ptx/ptx_test.go | 8 ++++---- internal/ptx/snowflake_test.go | 6 +++--- 16 files changed, 44 insertions(+), 44 deletions(-) delete mode 100644 internal/engine/netx/mockablex/doc.go rename internal/{engine/netx/mockablex => netxmocks}/conn.go (98%) rename internal/{engine/netx/mockablex => netxmocks}/conn_test.go (99%) rename internal/{engine/netx/mockablex => netxmocks}/dialer.go (96%) rename internal/{engine/netx/mockablex => netxmocks}/dialer_test.go (96%) create mode 100644 internal/netxmocks/doc.go diff --git a/internal/bytecounter/conn_test.go b/internal/bytecounter/conn_test.go index 4b93050..88bc67a 100644 --- a/internal/bytecounter/conn_test.go +++ b/internal/bytecounter/conn_test.go @@ -4,12 +4,12 @@ import ( "errors" "testing" - "github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex" + "github.com/ooni/probe-cli/v3/internal/netxmocks" ) func TestConnWorksOnSuccess(t *testing.T) { counter := New() - underlying := &mockablex.Conn{ + underlying := &netxmocks.Conn{ MockRead: func(b []byte) (int, error) { return 10, nil }, @@ -39,7 +39,7 @@ func TestConnWorksOnFailure(t *testing.T) { readError := errors.New("read error") writeError := errors.New("write error") counter := New() - underlying := &mockablex.Conn{ + underlying := &netxmocks.Conn{ MockRead: func(b []byte) (int, error) { return 0, readError }, diff --git a/internal/engine/legacy/netx/emitterdialer_test.go b/internal/engine/legacy/netx/emitterdialer_test.go index 0ba64c7..21b31fe 100644 --- a/internal/engine/legacy/netx/emitterdialer_test.go +++ b/internal/engine/legacy/netx/emitterdialer_test.go @@ -10,7 +10,7 @@ import ( "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/handlers" "github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/modelx" - "github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex" + "github.com/ooni/probe-cli/v3/internal/netxmocks" ) func TestEmitterFailure(t *testing.T) { @@ -20,7 +20,7 @@ func TestEmitterFailure(t *testing.T) { Beginning: time.Now(), Handler: saver, }) - d := EmitterDialer{Dialer: mockablex.Dialer{ + d := EmitterDialer{Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { return nil, io.EOF }, @@ -69,9 +69,9 @@ func TestEmitterSuccess(t *testing.T) { Beginning: time.Now(), Handler: saver, }) - d := EmitterDialer{Dialer: mockablex.Dialer{ + d := EmitterDialer{Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { - return &mockablex.Conn{ + return &netxmocks.Conn{ MockRead: func(b []byte) (int, error) { return 0, io.EOF }, diff --git a/internal/engine/netx/dialer/bytecounter_test.go b/internal/engine/netx/dialer/bytecounter_test.go index c9a64ec..be8f9a8 100644 --- a/internal/engine/netx/dialer/bytecounter_test.go +++ b/internal/engine/netx/dialer/bytecounter_test.go @@ -9,8 +9,8 @@ import ( "testing" "github.com/ooni/probe-cli/v3/internal/bytecounter" - "github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex" "github.com/ooni/probe-cli/v3/internal/iox" + "github.com/ooni/probe-cli/v3/internal/netxmocks" ) func dorequest(ctx context.Context, url string) error { @@ -76,7 +76,7 @@ func TestByteCounterNoHandlers(t *testing.T) { } func TestByteCounterConnectFailure(t *testing.T) { - dialer := &byteCounterDialer{Dialer: mockablex.Dialer{ + dialer := &byteCounterDialer{Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { return nil, io.EOF }, diff --git a/internal/engine/netx/dialer/errorwrapper_test.go b/internal/engine/netx/dialer/errorwrapper_test.go index 91b0ae1..9dafba4 100644 --- a/internal/engine/netx/dialer/errorwrapper_test.go +++ b/internal/engine/netx/dialer/errorwrapper_test.go @@ -8,12 +8,12 @@ import ( "testing" "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" - "github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex" + "github.com/ooni/probe-cli/v3/internal/netxmocks" ) func TestErrorWrapperFailure(t *testing.T) { ctx := context.Background() - d := &errorWrapperDialer{Dialer: mockablex.Dialer{ + d := &errorWrapperDialer{Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { return nil, io.EOF }, @@ -43,9 +43,9 @@ func errorWrapperCheckErr(t *testing.T, err error, op string) { func TestErrorWrapperSuccess(t *testing.T) { ctx := context.Background() - d := &errorWrapperDialer{Dialer: mockablex.Dialer{ + d := &errorWrapperDialer{Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { - return &mockablex.Conn{ + return &netxmocks.Conn{ MockRead: func(b []byte) (int, error) { return 0, io.EOF }, diff --git a/internal/engine/netx/dialer/proxy_test.go b/internal/engine/netx/dialer/proxy_test.go index 8ad7ee3..c1c2c38 100644 --- a/internal/engine/netx/dialer/proxy_test.go +++ b/internal/engine/netx/dialer/proxy_test.go @@ -8,13 +8,13 @@ import ( "net/url" "testing" - "github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex" + "github.com/ooni/probe-cli/v3/internal/netxmocks" ) func TestProxyDialerDialContextNoProxyURL(t *testing.T) { expected := errors.New("mocked error") d := &proxyDialer{ - Dialer: mockablex.Dialer{ + Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { return nil, expected }, @@ -45,7 +45,7 @@ func TestProxyDialerDialContextInvalidScheme(t *testing.T) { func TestProxyDialerDialContextWithEOF(t *testing.T) { const expect = "10.0.0.1:9050" d := &proxyDialer{ - Dialer: mockablex.Dialer{ + Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { if address != expect { return nil, errors.New("unexpected address") diff --git a/internal/engine/netx/dialer/saver_test.go b/internal/engine/netx/dialer/saver_test.go index 4dbee07..c66f716 100644 --- a/internal/engine/netx/dialer/saver_test.go +++ b/internal/engine/netx/dialer/saver_test.go @@ -9,15 +9,15 @@ import ( "time" "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" - "github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace" + "github.com/ooni/probe-cli/v3/internal/netxmocks" ) func TestSaverDialerFailure(t *testing.T) { expected := errors.New("mocked error") saver := &trace.Saver{} dlr := &saverDialer{ - Dialer: mockablex.Dialer{ + Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { return nil, expected }, @@ -59,7 +59,7 @@ func TestSaverConnDialerFailure(t *testing.T) { expected := errors.New("mocked error") saver := &trace.Saver{} dlr := &saverConnDialer{ - Dialer: mockablex.Dialer{ + Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { return nil, expected }, @@ -79,9 +79,9 @@ func TestSaverConnDialerSuccess(t *testing.T) { saver := &trace.Saver{} dlr := &saverConnDialer{ Dialer: &saverDialer{ - Dialer: mockablex.Dialer{ + Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { - return &mockablex.Conn{ + return &netxmocks.Conn{ MockRead: func(b []byte) (int, error) { return 0, io.EOF }, diff --git a/internal/engine/netx/mockablex/doc.go b/internal/engine/netx/mockablex/doc.go deleted file mode 100644 index 45b32d3..0000000 --- a/internal/engine/netx/mockablex/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package mockable contains mocks for netx types. -package mockablex diff --git a/internal/netxlite/dialer_test.go b/internal/netxlite/dialer_test.go index e07a81d..879d3b6 100644 --- a/internal/netxlite/dialer_test.go +++ b/internal/netxlite/dialer_test.go @@ -10,7 +10,7 @@ import ( "time" "github.com/apex/log" - "github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex" + "github.com/ooni/probe-cli/v3/internal/netxmocks" ) func TestDialerResolverNoPort(t *testing.T) { @@ -69,7 +69,7 @@ func (r MockableResolver) Address() string { } func TestDialerResolverDialForSingleIPFails(t *testing.T) { - dialer := &DialerResolver{Dialer: mockablex.Dialer{ + dialer := &DialerResolver{Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { return nil, io.EOF }, @@ -85,7 +85,7 @@ func TestDialerResolverDialForSingleIPFails(t *testing.T) { func TestDialerResolverDialForManyIPFails(t *testing.T) { dialer := &DialerResolver{ - Dialer: mockablex.Dialer{ + Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { return nil, io.EOF }, @@ -102,9 +102,9 @@ func TestDialerResolverDialForManyIPFails(t *testing.T) { } func TestDialerResolverDialForManyIPSuccess(t *testing.T) { - dialer := &DialerResolver{Dialer: mockablex.Dialer{ + dialer := &DialerResolver{Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { - return &mockablex.Conn{ + return &netxmocks.Conn{ MockClose: func() error { return nil }, @@ -125,7 +125,7 @@ func TestDialerResolverDialForManyIPSuccess(t *testing.T) { func TestDialerLoggerFailure(t *testing.T) { d := &DialerLogger{ - Dialer: mockablex.Dialer{ + Dialer: netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { return nil, io.EOF }, diff --git a/internal/engine/netx/mockablex/conn.go b/internal/netxmocks/conn.go similarity index 98% rename from internal/engine/netx/mockablex/conn.go rename to internal/netxmocks/conn.go index 1e369eb..77826ad 100644 --- a/internal/engine/netx/mockablex/conn.go +++ b/internal/netxmocks/conn.go @@ -1,4 +1,4 @@ -package mockablex +package netxmocks import ( "net" diff --git a/internal/engine/netx/mockablex/conn_test.go b/internal/netxmocks/conn_test.go similarity index 99% rename from internal/engine/netx/mockablex/conn_test.go rename to internal/netxmocks/conn_test.go index b438ccd..bab1599 100644 --- a/internal/engine/netx/mockablex/conn_test.go +++ b/internal/netxmocks/conn_test.go @@ -1,4 +1,4 @@ -package mockablex +package netxmocks import ( "errors" diff --git a/internal/engine/netx/mockablex/dialer.go b/internal/netxmocks/dialer.go similarity index 96% rename from internal/engine/netx/mockablex/dialer.go rename to internal/netxmocks/dialer.go index dd9a58f..0875ac6 100644 --- a/internal/engine/netx/mockablex/dialer.go +++ b/internal/netxmocks/dialer.go @@ -1,4 +1,4 @@ -package mockablex +package netxmocks import ( "context" diff --git a/internal/engine/netx/mockablex/dialer_test.go b/internal/netxmocks/dialer_test.go similarity index 96% rename from internal/engine/netx/mockablex/dialer_test.go rename to internal/netxmocks/dialer_test.go index b9c3a83..4ea7545 100644 --- a/internal/engine/netx/mockablex/dialer_test.go +++ b/internal/netxmocks/dialer_test.go @@ -1,4 +1,4 @@ -package mockablex +package netxmocks import ( "context" diff --git a/internal/netxmocks/doc.go b/internal/netxmocks/doc.go new file mode 100644 index 0000000..5db7bff --- /dev/null +++ b/internal/netxmocks/doc.go @@ -0,0 +1,2 @@ +// Package netxmocks contains mocks for netx types. +package netxmocks diff --git a/internal/ptx/obfs4_test.go b/internal/ptx/obfs4_test.go index cdd6a28..e07325b 100644 --- a/internal/ptx/obfs4_test.go +++ b/internal/ptx/obfs4_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/ooni/probe-cli/v3/internal/atomicx" - "github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex" + "github.com/ooni/probe-cli/v3/internal/netxmocks" ) func TestOBFS4DialerWorks(t *testing.T) { @@ -48,7 +48,7 @@ func TestOBFS4DialerFailsWithInvalidCert(t *testing.T) { func TestOBFS4DialerFailsWithConnectionErrorAndNoContextExpiration(t *testing.T) { expected := errors.New("mocked error") o4d := DefaultTestingOBFS4Bridge() - o4d.UnderlyingDialer = &mockablex.Dialer{ + o4d.UnderlyingDialer = &netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { return nil, expected }, @@ -67,7 +67,7 @@ func TestOBFS4DialerFailsWithConnectionErrorAndContextExpiration(t *testing.T) { defer cancel() expected := errors.New("mocked error") o4d := DefaultTestingOBFS4Bridge() - o4d.UnderlyingDialer = &mockablex.Dialer{ + o4d.UnderlyingDialer = &netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { // We cancel the context before returning the error, which makes // the context cancellation happen before us returning. @@ -101,7 +101,7 @@ func TestOBFS4DialerWorksWithContextExpiration(t *testing.T) { defer cancel() called := &atomicx.Int64{} o4d := DefaultTestingOBFS4Bridge() - o4d.UnderlyingDialer = &mockablex.Dialer{ + o4d.UnderlyingDialer = &netxmocks.Dialer{ MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) { // We cancel the context before returning the error, which makes // the context cancellation happen before us returning. diff --git a/internal/ptx/ptx_test.go b/internal/ptx/ptx_test.go index 64f5bc6..39fe6b9 100644 --- a/internal/ptx/ptx_test.go +++ b/internal/ptx/ptx_test.go @@ -13,8 +13,8 @@ import ( "github.com/apex/log" "github.com/ooni/probe-cli/v3/internal/atomicx" - "github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex" "github.com/ooni/probe-cli/v3/internal/iox" + "github.com/ooni/probe-cli/v3/internal/netxmocks" ) func TestListenerLoggerWorks(t *testing.T) { @@ -96,8 +96,8 @@ func TestListenerCastListenerWorksFineOnError(t *testing.T) { // mockableSocksConn is a mockable ptxSocksConn. type mockableSocksConn struct { - // mockablex.Conn allows to mock all net.Conn functionality. - *mockablex.Conn + // netxmocks.Conn allows to mock all net.Conn functionality. + *netxmocks.Conn // MockGrant allows to mock the Grant function. MockGrant func(addr *net.TCPAddr) error @@ -160,7 +160,7 @@ func TestListenerHandleSocksConnWithDialContextFailure(t *testing.T) { } lst := &Listener{PTDialer: d} c := &mockableSocksConn{ - Conn: &mockablex.Conn{ + Conn: &netxmocks.Conn{ MockClose: func() error { return nil }, diff --git a/internal/ptx/snowflake_test.go b/internal/ptx/snowflake_test.go index 0c8f4e2..1b33005 100644 --- a/internal/ptx/snowflake_test.go +++ b/internal/ptx/snowflake_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/ooni/probe-cli/v3/internal/atomicx" - "github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex" + "github.com/ooni/probe-cli/v3/internal/netxmocks" ) func TestSnowflakeDialerWorks(t *testing.T) { @@ -50,7 +50,7 @@ func TestSnowflakeDialerWorksWithMocks(t *testing.T) { newClientTransport: func(brokerURL, frontDomain string, iceAddresses []string, keepLocalAddresses bool, maxSnowflakes int) (snowflakeTransport, error) { return &mockableSnowflakeTransport{ MockDial: func() (net.Conn, error) { - return &mockablex.Conn{ + return &netxmocks.Conn{ MockClose: func() error { return nil }, @@ -144,7 +144,7 @@ func TestSnowflakeDialerWorksWithWithCancelledContext(t *testing.T) { return &mockableSnowflakeTransport{ MockDial: func() (net.Conn, error) { cancel() // cause a cancel before we can really have a conn - return &mockablex.Conn{ + return &netxmocks.Conn{ MockClose: func() error { called.Add(1) return nil