refactor(netxlite/mocks): group tests, fix naming inconsistencies (#485)
Part of https://github.com/ooni/probe/issues/1591
This commit is contained in:
parent
9e82e37ab8
commit
f054ec3201
@ -48,7 +48,7 @@ func TestErrorWrapperQUICListenerFailure(t *testing.T) {
|
|||||||
|
|
||||||
func TestErrorWrapperUDPConnWriteToSuccess(t *testing.T) {
|
func TestErrorWrapperUDPConnWriteToSuccess(t *testing.T) {
|
||||||
quc := &errorWrapperUDPConn{
|
quc := &errorWrapperUDPConn{
|
||||||
UDPLikeConn: &mocks.QUICUDPConn{
|
UDPLikeConn: &mocks.QUICUDPLikeConn{
|
||||||
MockWriteTo: func(p []byte, addr net.Addr) (int, error) {
|
MockWriteTo: func(p []byte, addr net.Addr) (int, error) {
|
||||||
return 10, nil
|
return 10, nil
|
||||||
},
|
},
|
||||||
@ -68,7 +68,7 @@ func TestErrorWrapperUDPConnWriteToSuccess(t *testing.T) {
|
|||||||
func TestErrorWrapperUDPConnWriteToFailure(t *testing.T) {
|
func TestErrorWrapperUDPConnWriteToFailure(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
quc := &errorWrapperUDPConn{
|
quc := &errorWrapperUDPConn{
|
||||||
UDPLikeConn: &mocks.QUICUDPConn{
|
UDPLikeConn: &mocks.QUICUDPLikeConn{
|
||||||
MockWriteTo: func(p []byte, addr net.Addr) (int, error) {
|
MockWriteTo: func(p []byte, addr net.Addr) (int, error) {
|
||||||
return 0, expected
|
return 0, expected
|
||||||
},
|
},
|
||||||
@ -88,7 +88,7 @@ func TestErrorWrapperUDPConnWriteToFailure(t *testing.T) {
|
|||||||
func TestErrorWrapperUDPConnReadFromSuccess(t *testing.T) {
|
func TestErrorWrapperUDPConnReadFromSuccess(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
quc := &errorWrapperUDPConn{
|
quc := &errorWrapperUDPConn{
|
||||||
UDPLikeConn: &mocks.QUICUDPConn{
|
UDPLikeConn: &mocks.QUICUDPLikeConn{
|
||||||
MockReadFrom: func(b []byte) (int, net.Addr, error) {
|
MockReadFrom: func(b []byte) (int, net.Addr, error) {
|
||||||
return 0, nil, expected
|
return 0, nil, expected
|
||||||
},
|
},
|
||||||
@ -109,7 +109,7 @@ func TestErrorWrapperUDPConnReadFromSuccess(t *testing.T) {
|
|||||||
|
|
||||||
func TestErrorWrapperUDPConnReadFromFailure(t *testing.T) {
|
func TestErrorWrapperUDPConnReadFromFailure(t *testing.T) {
|
||||||
quc := &errorWrapperUDPConn{
|
quc := &errorWrapperUDPConn{
|
||||||
UDPLikeConn: &mocks.QUICUDPConn{
|
UDPLikeConn: &mocks.QUICUDPLikeConn{
|
||||||
MockReadFrom: func(b []byte) (int, net.Addr, error) {
|
MockReadFrom: func(b []byte) (int, net.Addr, error) {
|
||||||
return 10, nil, nil
|
return 10, nil, nil
|
||||||
},
|
},
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
package mocks
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Conn is a mockable net.Conn.
|
|
||||||
type Conn struct {
|
|
||||||
MockRead func(b []byte) (int, error)
|
|
||||||
MockWrite func(b []byte) (int, error)
|
|
||||||
MockClose func() error
|
|
||||||
MockLocalAddr func() net.Addr
|
|
||||||
MockRemoteAddr func() net.Addr
|
|
||||||
MockSetDeadline func(t time.Time) error
|
|
||||||
MockSetReadDeadline func(t time.Time) error
|
|
||||||
MockSetWriteDeadline func(t time.Time) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read calls MockRead.
|
|
||||||
func (c *Conn) Read(b []byte) (int, error) {
|
|
||||||
return c.MockRead(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write calls MockWrite.
|
|
||||||
func (c *Conn) Write(b []byte) (int, error) {
|
|
||||||
return c.MockWrite(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close calls MockClose.
|
|
||||||
func (c *Conn) Close() error {
|
|
||||||
return c.MockClose()
|
|
||||||
}
|
|
||||||
|
|
||||||
// LocalAddr calls MockLocalAddr.
|
|
||||||
func (c *Conn) LocalAddr() net.Addr {
|
|
||||||
return c.MockLocalAddr()
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoteAddr calls MockRemoteAddr.
|
|
||||||
func (c *Conn) RemoteAddr() net.Addr {
|
|
||||||
return c.MockRemoteAddr()
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDeadline calls MockSetDeadline.
|
|
||||||
func (c *Conn) SetDeadline(t time.Time) error {
|
|
||||||
return c.MockSetDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetReadDeadline calls MockSetReadDeadline.
|
|
||||||
func (c *Conn) SetReadDeadline(t time.Time) error {
|
|
||||||
return c.MockSetReadDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetWriteDeadline calls MockSetWriteDeadline.
|
|
||||||
func (c *Conn) SetWriteDeadline(t time.Time) error {
|
|
||||||
return c.MockSetWriteDeadline(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ net.Conn = &Conn{}
|
|
@ -1,126 +0,0 @@
|
|||||||
package mocks
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"net"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestConnReadWorks(t *testing.T) {
|
|
||||||
expected := errors.New("mocked error")
|
|
||||||
c := &Conn{
|
|
||||||
MockRead: func(b []byte) (int, error) {
|
|
||||||
return 0, expected
|
|
||||||
},
|
|
||||||
}
|
|
||||||
count, err := c.Read(make([]byte, 128))
|
|
||||||
if !errors.Is(err, expected) {
|
|
||||||
t.Fatal("not the error we expected")
|
|
||||||
}
|
|
||||||
if count != 0 {
|
|
||||||
t.Fatal("expected 0 bytes")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConnWriteWorks(t *testing.T) {
|
|
||||||
expected := errors.New("mocked error")
|
|
||||||
c := &Conn{
|
|
||||||
MockWrite: func(b []byte) (int, error) {
|
|
||||||
return 0, expected
|
|
||||||
},
|
|
||||||
}
|
|
||||||
count, err := c.Write(make([]byte, 128))
|
|
||||||
if !errors.Is(err, expected) {
|
|
||||||
t.Fatal("not the error we expected")
|
|
||||||
}
|
|
||||||
if count != 0 {
|
|
||||||
t.Fatal("expected 0 bytes")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConnCloseWorks(t *testing.T) {
|
|
||||||
expected := errors.New("mocked error")
|
|
||||||
c := &Conn{
|
|
||||||
MockClose: func() error {
|
|
||||||
return expected
|
|
||||||
},
|
|
||||||
}
|
|
||||||
err := c.Close()
|
|
||||||
if !errors.Is(err, expected) {
|
|
||||||
t.Fatal("not the error we expected")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConnLocalAddrWorks(t *testing.T) {
|
|
||||||
expected := &net.TCPAddr{
|
|
||||||
IP: net.IPv6loopback,
|
|
||||||
Port: 1234,
|
|
||||||
}
|
|
||||||
c := &Conn{
|
|
||||||
MockLocalAddr: func() net.Addr {
|
|
||||||
return expected
|
|
||||||
},
|
|
||||||
}
|
|
||||||
out := c.LocalAddr()
|
|
||||||
if diff := cmp.Diff(expected, out); diff != "" {
|
|
||||||
t.Fatal(diff)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConnRemoteAddrWorks(t *testing.T) {
|
|
||||||
expected := &net.TCPAddr{
|
|
||||||
IP: net.IPv6loopback,
|
|
||||||
Port: 1234,
|
|
||||||
}
|
|
||||||
c := &Conn{
|
|
||||||
MockRemoteAddr: func() net.Addr {
|
|
||||||
return expected
|
|
||||||
},
|
|
||||||
}
|
|
||||||
out := c.RemoteAddr()
|
|
||||||
if diff := cmp.Diff(expected, out); diff != "" {
|
|
||||||
t.Fatal(diff)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConnSetDeadline(t *testing.T) {
|
|
||||||
expected := errors.New("mocked error")
|
|
||||||
c := &Conn{
|
|
||||||
MockSetDeadline: func(t time.Time) error {
|
|
||||||
return expected
|
|
||||||
},
|
|
||||||
}
|
|
||||||
err := c.SetDeadline(time.Time{})
|
|
||||||
if !errors.Is(err, expected) {
|
|
||||||
t.Fatal("not the error we expected", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConnSetReadDeadline(t *testing.T) {
|
|
||||||
expected := errors.New("mocked error")
|
|
||||||
c := &Conn{
|
|
||||||
MockSetReadDeadline: func(t time.Time) error {
|
|
||||||
return expected
|
|
||||||
},
|
|
||||||
}
|
|
||||||
err := c.SetReadDeadline(time.Time{})
|
|
||||||
if !errors.Is(err, expected) {
|
|
||||||
t.Fatal("not the error we expected", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConnSetWriteDeadline(t *testing.T) {
|
|
||||||
expected := errors.New("mocked error")
|
|
||||||
c := &Conn{
|
|
||||||
MockSetWriteDeadline: func(t time.Time) error {
|
|
||||||
return expected
|
|
||||||
},
|
|
||||||
}
|
|
||||||
err := c.SetWriteDeadline(time.Time{})
|
|
||||||
if !errors.Is(err, expected) {
|
|
||||||
t.Fatal("not the error we expected", err)
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,6 +3,7 @@ package mocks
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
"net"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Dialer is a mockable Dialer.
|
// Dialer is a mockable Dialer.
|
||||||
@ -20,3 +21,57 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.
|
|||||||
func (d *Dialer) CloseIdleConnections() {
|
func (d *Dialer) CloseIdleConnections() {
|
||||||
d.MockCloseIdleConnections()
|
d.MockCloseIdleConnections()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Conn is a mockable net.Conn.
|
||||||
|
type Conn struct {
|
||||||
|
MockRead func(b []byte) (int, error)
|
||||||
|
MockWrite func(b []byte) (int, error)
|
||||||
|
MockClose func() error
|
||||||
|
MockLocalAddr func() net.Addr
|
||||||
|
MockRemoteAddr func() net.Addr
|
||||||
|
MockSetDeadline func(t time.Time) error
|
||||||
|
MockSetReadDeadline func(t time.Time) error
|
||||||
|
MockSetWriteDeadline func(t time.Time) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read calls MockRead.
|
||||||
|
func (c *Conn) Read(b []byte) (int, error) {
|
||||||
|
return c.MockRead(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write calls MockWrite.
|
||||||
|
func (c *Conn) Write(b []byte) (int, error) {
|
||||||
|
return c.MockWrite(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close calls MockClose.
|
||||||
|
func (c *Conn) Close() error {
|
||||||
|
return c.MockClose()
|
||||||
|
}
|
||||||
|
|
||||||
|
// LocalAddr calls MockLocalAddr.
|
||||||
|
func (c *Conn) LocalAddr() net.Addr {
|
||||||
|
return c.MockLocalAddr()
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoteAddr calls MockRemoteAddr.
|
||||||
|
func (c *Conn) RemoteAddr() net.Addr {
|
||||||
|
return c.MockRemoteAddr()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDeadline calls MockSetDeadline.
|
||||||
|
func (c *Conn) SetDeadline(t time.Time) error {
|
||||||
|
return c.MockSetDeadline(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetReadDeadline calls MockSetReadDeadline.
|
||||||
|
func (c *Conn) SetReadDeadline(t time.Time) error {
|
||||||
|
return c.MockSetReadDeadline(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetWriteDeadline calls MockSetWriteDeadline.
|
||||||
|
func (c *Conn) SetWriteDeadline(t time.Time) error {
|
||||||
|
return c.MockSetWriteDeadline(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ net.Conn = &Conn{}
|
||||||
|
@ -5,9 +5,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDialerDialContext(t *testing.T) {
|
func TestDialer(t *testing.T) {
|
||||||
|
t.Run("DialContext", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
d := Dialer{
|
d := Dialer{
|
||||||
MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) {
|
MockDialContext: func(ctx context.Context, network string, address string) (net.Conn, error) {
|
||||||
@ -22,9 +26,9 @@ func TestDialerDialContext(t *testing.T) {
|
|||||||
if conn != nil {
|
if conn != nil {
|
||||||
t.Fatal("expected nil conn")
|
t.Fatal("expected nil conn")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestDialerCloseIdleConnections(t *testing.T) {
|
t.Run("CloseIdleConnections", func(t *testing.T) {
|
||||||
var called bool
|
var called bool
|
||||||
d := &Dialer{
|
d := &Dialer{
|
||||||
MockCloseIdleConnections: func() {
|
MockCloseIdleConnections: func() {
|
||||||
@ -35,4 +39,123 @@ func TestDialerCloseIdleConnections(t *testing.T) {
|
|||||||
if !called {
|
if !called {
|
||||||
t.Fatal("not called")
|
t.Fatal("not called")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConn(t *testing.T) {
|
||||||
|
t.Run("Read", func(t *testing.T) {
|
||||||
|
expected := errors.New("mocked error")
|
||||||
|
c := &Conn{
|
||||||
|
MockRead: func(b []byte) (int, error) {
|
||||||
|
return 0, expected
|
||||||
|
},
|
||||||
|
}
|
||||||
|
count, err := c.Read(make([]byte, 128))
|
||||||
|
if !errors.Is(err, expected) {
|
||||||
|
t.Fatal("not the error we expected")
|
||||||
|
}
|
||||||
|
if count != 0 {
|
||||||
|
t.Fatal("expected 0 bytes")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Write", func(t *testing.T) {
|
||||||
|
expected := errors.New("mocked error")
|
||||||
|
c := &Conn{
|
||||||
|
MockWrite: func(b []byte) (int, error) {
|
||||||
|
return 0, expected
|
||||||
|
},
|
||||||
|
}
|
||||||
|
count, err := c.Write(make([]byte, 128))
|
||||||
|
if !errors.Is(err, expected) {
|
||||||
|
t.Fatal("not the error we expected")
|
||||||
|
}
|
||||||
|
if count != 0 {
|
||||||
|
t.Fatal("expected 0 bytes")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Close", func(t *testing.T) {
|
||||||
|
expected := errors.New("mocked error")
|
||||||
|
c := &Conn{
|
||||||
|
MockClose: func() error {
|
||||||
|
return expected
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := c.Close()
|
||||||
|
if !errors.Is(err, expected) {
|
||||||
|
t.Fatal("not the error we expected")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("LocalAddr", func(t *testing.T) {
|
||||||
|
expected := &net.TCPAddr{
|
||||||
|
IP: net.IPv6loopback,
|
||||||
|
Port: 1234,
|
||||||
|
}
|
||||||
|
c := &Conn{
|
||||||
|
MockLocalAddr: func() net.Addr {
|
||||||
|
return expected
|
||||||
|
},
|
||||||
|
}
|
||||||
|
out := c.LocalAddr()
|
||||||
|
if diff := cmp.Diff(expected, out); diff != "" {
|
||||||
|
t.Fatal(diff)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("RemoteAddr", func(t *testing.T) {
|
||||||
|
expected := &net.TCPAddr{
|
||||||
|
IP: net.IPv6loopback,
|
||||||
|
Port: 1234,
|
||||||
|
}
|
||||||
|
c := &Conn{
|
||||||
|
MockRemoteAddr: func() net.Addr {
|
||||||
|
return expected
|
||||||
|
},
|
||||||
|
}
|
||||||
|
out := c.RemoteAddr()
|
||||||
|
if diff := cmp.Diff(expected, out); diff != "" {
|
||||||
|
t.Fatal(diff)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SetDeadline", func(t *testing.T) {
|
||||||
|
expected := errors.New("mocked error")
|
||||||
|
c := &Conn{
|
||||||
|
MockSetDeadline: func(t time.Time) error {
|
||||||
|
return expected
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := c.SetDeadline(time.Time{})
|
||||||
|
if !errors.Is(err, expected) {
|
||||||
|
t.Fatal("not the error we expected", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SetReadDeadline", func(t *testing.T) {
|
||||||
|
expected := errors.New("mocked error")
|
||||||
|
c := &Conn{
|
||||||
|
MockSetReadDeadline: func(t time.Time) error {
|
||||||
|
return expected
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := c.SetReadDeadline(time.Time{})
|
||||||
|
if !errors.Is(err, expected) {
|
||||||
|
t.Fatal("not the error we expected", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SetWriteDeadline", func(t *testing.T) {
|
||||||
|
expected := errors.New("mocked error")
|
||||||
|
c := &Conn{
|
||||||
|
MockSetWriteDeadline: func(t time.Time) error {
|
||||||
|
return expected
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := c.SetWriteDeadline(time.Time{})
|
||||||
|
if !errors.Is(err, expected) {
|
||||||
|
t.Fatal("not the error we expected", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,8 @@ import (
|
|||||||
"github.com/ooni/probe-cli/v3/internal/atomicx"
|
"github.com/ooni/probe-cli/v3/internal/atomicx"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHTTPTransportRoundTrip(t *testing.T) {
|
func TestHTTPTransport(t *testing.T) {
|
||||||
|
t.Run("RoundTrip", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
txp := &HTTPTransport{
|
txp := &HTTPTransport{
|
||||||
MockRoundTrip: func(req *http.Request) (*http.Response, error) {
|
MockRoundTrip: func(req *http.Request) (*http.Response, error) {
|
||||||
@ -22,9 +23,9 @@ func TestHTTPTransportRoundTrip(t *testing.T) {
|
|||||||
if resp != nil {
|
if resp != nil {
|
||||||
t.Fatal("expected nil response here")
|
t.Fatal("expected nil response here")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestHTTPTransportCloseIdleConnections(t *testing.T) {
|
t.Run("CloseIdleConnections", func(t *testing.T) {
|
||||||
called := &atomicx.Int64{}
|
called := &atomicx.Int64{}
|
||||||
txp := &HTTPTransport{
|
txp := &HTTPTransport{
|
||||||
MockCloseIdleConnections: func() {
|
MockCloseIdleConnections: func() {
|
||||||
@ -35,4 +36,5 @@ func TestHTTPTransportCloseIdleConnections(t *testing.T) {
|
|||||||
if called.Load() != 1 {
|
if called.Load() != 1 {
|
||||||
t.Fatal("not called")
|
t.Fatal("not called")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,8 @@ import (
|
|||||||
"github.com/lucas-clemente/quic-go"
|
"github.com/lucas-clemente/quic-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestQUICContextDialerDialContext(t *testing.T) {
|
func TestQUICContextDialer(t *testing.T) {
|
||||||
|
t.Run("DialContext", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
qcd := &QUICContextDialer{
|
qcd := &QUICContextDialer{
|
||||||
MockDialContext: func(ctx context.Context, network string, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
|
MockDialContext: func(ctx context.Context, network string, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
|
||||||
@ -26,4 +27,5 @@ func TestQUICContextDialerDialContext(t *testing.T) {
|
|||||||
if sess != nil {
|
if sess != nil {
|
||||||
t.Fatal("expected nil session")
|
t.Fatal("expected nil session")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -139,8 +139,8 @@ func (s *QUICEarlySession) ReceiveMessage() ([]byte, error) {
|
|||||||
return s.MockReceiveMessage()
|
return s.MockReceiveMessage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// QUICUDPConn is an UDP conn used by QUIC.
|
// QUICUDPLikeConn is an UDP conn used by QUIC.
|
||||||
type QUICUDPConn struct {
|
type QUICUDPLikeConn struct {
|
||||||
MockWriteTo func(p []byte, addr net.Addr) (int, error)
|
MockWriteTo func(p []byte, addr net.Addr) (int, error)
|
||||||
MockClose func() error
|
MockClose func() error
|
||||||
MockLocalAddr func() net.Addr
|
MockLocalAddr func() net.Addr
|
||||||
@ -153,54 +153,54 @@ type QUICUDPConn struct {
|
|||||||
MockSetReadBuffer func(n int) error
|
MockSetReadBuffer func(n int) error
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ quicx.UDPLikeConn = &QUICUDPConn{}
|
var _ quicx.UDPLikeConn = &QUICUDPLikeConn{}
|
||||||
|
|
||||||
// WriteTo calls MockWriteTo.
|
// WriteTo calls MockWriteTo.
|
||||||
func (c *QUICUDPConn) WriteTo(p []byte, addr net.Addr) (int, error) {
|
func (c *QUICUDPLikeConn) WriteTo(p []byte, addr net.Addr) (int, error) {
|
||||||
return c.MockWriteTo(p, addr)
|
return c.MockWriteTo(p, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close calls MockClose.
|
// Close calls MockClose.
|
||||||
func (c *QUICUDPConn) Close() error {
|
func (c *QUICUDPLikeConn) Close() error {
|
||||||
return c.MockClose()
|
return c.MockClose()
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocalAddr calls MockLocalAddr.
|
// LocalAddr calls MockLocalAddr.
|
||||||
func (c *QUICUDPConn) LocalAddr() net.Addr {
|
func (c *QUICUDPLikeConn) LocalAddr() net.Addr {
|
||||||
return c.MockLocalAddr()
|
return c.MockLocalAddr()
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteAddr calls MockRemoteAddr.
|
// RemoteAddr calls MockRemoteAddr.
|
||||||
func (c *QUICUDPConn) RemoteAddr() net.Addr {
|
func (c *QUICUDPLikeConn) RemoteAddr() net.Addr {
|
||||||
return c.MockRemoteAddr()
|
return c.MockRemoteAddr()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDeadline calls MockSetDeadline.
|
// SetDeadline calls MockSetDeadline.
|
||||||
func (c *QUICUDPConn) SetDeadline(t time.Time) error {
|
func (c *QUICUDPLikeConn) SetDeadline(t time.Time) error {
|
||||||
return c.MockSetDeadline(t)
|
return c.MockSetDeadline(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetReadDeadline calls MockSetReadDeadline.
|
// SetReadDeadline calls MockSetReadDeadline.
|
||||||
func (c *QUICUDPConn) SetReadDeadline(t time.Time) error {
|
func (c *QUICUDPLikeConn) SetReadDeadline(t time.Time) error {
|
||||||
return c.MockSetReadDeadline(t)
|
return c.MockSetReadDeadline(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetWriteDeadline calls MockSetWriteDeadline.
|
// SetWriteDeadline calls MockSetWriteDeadline.
|
||||||
func (c *QUICUDPConn) SetWriteDeadline(t time.Time) error {
|
func (c *QUICUDPLikeConn) SetWriteDeadline(t time.Time) error {
|
||||||
return c.MockSetWriteDeadline(t)
|
return c.MockSetWriteDeadline(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadFrom calls MockReadFrom.
|
// ReadFrom calls MockReadFrom.
|
||||||
func (c *QUICUDPConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
func (c *QUICUDPLikeConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||||
return c.MockReadFrom(b)
|
return c.MockReadFrom(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SyscallConn calls MockSyscallConn.
|
// SyscallConn calls MockSyscallConn.
|
||||||
func (c *QUICUDPConn) SyscallConn() (syscall.RawConn, error) {
|
func (c *QUICUDPLikeConn) SyscallConn() (syscall.RawConn, error) {
|
||||||
return c.MockSyscallConn()
|
return c.MockSyscallConn()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetReadBuffer calls MockSetReadBuffer.
|
// SetReadBuffer calls MockSetReadBuffer.
|
||||||
func (c *QUICUDPConn) SetReadBuffer(n int) error {
|
func (c *QUICUDPLikeConn) SetReadBuffer(n int) error {
|
||||||
return c.MockSetReadBuffer(n)
|
return c.MockSetReadBuffer(n)
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestQUICListenerListen(t *testing.T) {
|
func TestQUICListenerListen(t *testing.T) {
|
||||||
|
t.Run("Listen", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
ql := &QUICListener{
|
ql := &QUICListener{
|
||||||
MockListen: func(addr *net.UDPAddr) (quicx.UDPLikeConn, error) {
|
MockListen: func(addr *net.UDPAddr) (quicx.UDPLikeConn, error) {
|
||||||
@ -29,9 +30,11 @@ func TestQUICListenerListen(t *testing.T) {
|
|||||||
if pconn != nil {
|
if pconn != nil {
|
||||||
t.Fatal("expected nil conn here")
|
t.Fatal("expected nil conn here")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQUICDialerDialContext(t *testing.T) {
|
func TestQUICDialer(t *testing.T) {
|
||||||
|
t.Run("DialContext", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
qcd := &QUICDialer{
|
qcd := &QUICDialer{
|
||||||
MockDialContext: func(ctx context.Context, network string, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
|
MockDialContext: func(ctx context.Context, network string, address string, tlsConfig *tls.Config, quicConfig *quic.Config) (quic.EarlySession, error) {
|
||||||
@ -48,9 +51,9 @@ func TestQUICDialerDialContext(t *testing.T) {
|
|||||||
if sess != nil {
|
if sess != nil {
|
||||||
t.Fatal("expected nil session")
|
t.Fatal("expected nil session")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICDialerCloseIdleConnections(t *testing.T) {
|
t.Run("CloseIdleConnections", func(t *testing.T) {
|
||||||
var called bool
|
var called bool
|
||||||
qcd := &QUICDialer{
|
qcd := &QUICDialer{
|
||||||
MockCloseIdleConnections: func() {
|
MockCloseIdleConnections: func() {
|
||||||
@ -61,9 +64,11 @@ func TestQUICDialerCloseIdleConnections(t *testing.T) {
|
|||||||
if !called {
|
if !called {
|
||||||
t.Fatal("not called")
|
t.Fatal("not called")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQUICEarlySessionAcceptStream(t *testing.T) {
|
func TestQUICEarlySession(t *testing.T) {
|
||||||
|
t.Run("AcceptStream", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockAcceptStream: func(ctx context.Context) (quic.Stream, error) {
|
MockAcceptStream: func(ctx context.Context) (quic.Stream, error) {
|
||||||
@ -78,9 +83,9 @@ func TestQUICEarlySessionAcceptStream(t *testing.T) {
|
|||||||
if stream != nil {
|
if stream != nil {
|
||||||
t.Fatal("expected nil stream here")
|
t.Fatal("expected nil stream here")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionAcceptUniStream(t *testing.T) {
|
t.Run("AcceptUniStream", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockAcceptUniStream: func(ctx context.Context) (quic.ReceiveStream, error) {
|
MockAcceptUniStream: func(ctx context.Context) (quic.ReceiveStream, error) {
|
||||||
@ -95,9 +100,9 @@ func TestQUICEarlySessionAcceptUniStream(t *testing.T) {
|
|||||||
if stream != nil {
|
if stream != nil {
|
||||||
t.Fatal("expected nil stream here")
|
t.Fatal("expected nil stream here")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionOpenStream(t *testing.T) {
|
t.Run("OpenStream", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockOpenStream: func() (quic.Stream, error) {
|
MockOpenStream: func() (quic.Stream, error) {
|
||||||
@ -111,9 +116,9 @@ func TestQUICEarlySessionOpenStream(t *testing.T) {
|
|||||||
if stream != nil {
|
if stream != nil {
|
||||||
t.Fatal("expected nil stream here")
|
t.Fatal("expected nil stream here")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionOpenStreamSync(t *testing.T) {
|
t.Run("OpenStreamSync", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockOpenStreamSync: func(ctx context.Context) (quic.Stream, error) {
|
MockOpenStreamSync: func(ctx context.Context) (quic.Stream, error) {
|
||||||
@ -128,9 +133,9 @@ func TestQUICEarlySessionOpenStreamSync(t *testing.T) {
|
|||||||
if stream != nil {
|
if stream != nil {
|
||||||
t.Fatal("expected nil stream here")
|
t.Fatal("expected nil stream here")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionOpenUniStream(t *testing.T) {
|
t.Run("OpenUniStream", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockOpenUniStream: func() (quic.SendStream, error) {
|
MockOpenUniStream: func() (quic.SendStream, error) {
|
||||||
@ -144,9 +149,9 @@ func TestQUICEarlySessionOpenUniStream(t *testing.T) {
|
|||||||
if stream != nil {
|
if stream != nil {
|
||||||
t.Fatal("expected nil stream here")
|
t.Fatal("expected nil stream here")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionOpenUniStreamSync(t *testing.T) {
|
t.Run("OpenUniStreamSync", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockOpenUniStreamSync: func(ctx context.Context) (quic.SendStream, error) {
|
MockOpenUniStreamSync: func(ctx context.Context) (quic.SendStream, error) {
|
||||||
@ -161,9 +166,9 @@ func TestQUICEarlySessionOpenUniStreamSync(t *testing.T) {
|
|||||||
if stream != nil {
|
if stream != nil {
|
||||||
t.Fatal("expected nil stream here")
|
t.Fatal("expected nil stream here")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionLocalAddr(t *testing.T) {
|
t.Run("LocalAddr", func(t *testing.T) {
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockLocalAddr: func() net.Addr {
|
MockLocalAddr: func() net.Addr {
|
||||||
return &net.UDPAddr{}
|
return &net.UDPAddr{}
|
||||||
@ -173,9 +178,9 @@ func TestQUICEarlySessionLocalAddr(t *testing.T) {
|
|||||||
if !reflect.ValueOf(addr).Elem().IsZero() {
|
if !reflect.ValueOf(addr).Elem().IsZero() {
|
||||||
t.Fatal("expected a zero address here")
|
t.Fatal("expected a zero address here")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionRemoteAddr(t *testing.T) {
|
t.Run("RemoteAddr", func(t *testing.T) {
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockRemoteAddr: func() net.Addr {
|
MockRemoteAddr: func() net.Addr {
|
||||||
return &net.UDPAddr{}
|
return &net.UDPAddr{}
|
||||||
@ -185,9 +190,9 @@ func TestQUICEarlySessionRemoteAddr(t *testing.T) {
|
|||||||
if !reflect.ValueOf(addr).Elem().IsZero() {
|
if !reflect.ValueOf(addr).Elem().IsZero() {
|
||||||
t.Fatal("expected a zero address here")
|
t.Fatal("expected a zero address here")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionCloseWithError(t *testing.T) {
|
t.Run("CloseWithError", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockCloseWithError: func(
|
MockCloseWithError: func(
|
||||||
@ -199,9 +204,9 @@ func TestQUICEarlySessionCloseWithError(t *testing.T) {
|
|||||||
if !errors.Is(err, expected) {
|
if !errors.Is(err, expected) {
|
||||||
t.Fatal("not the error we expected", err)
|
t.Fatal("not the error we expected", err)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionContext(t *testing.T) {
|
t.Run("Context", func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockContext: func() context.Context {
|
MockContext: func() context.Context {
|
||||||
@ -212,9 +217,9 @@ func TestQUICEarlySessionContext(t *testing.T) {
|
|||||||
if !reflect.DeepEqual(ctx, out) {
|
if !reflect.DeepEqual(ctx, out) {
|
||||||
t.Fatal("not the context we expected")
|
t.Fatal("not the context we expected")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionConnectionState(t *testing.T) {
|
t.Run("ConnectionState", func(t *testing.T) {
|
||||||
state := quic.ConnectionState{SupportsDatagrams: true}
|
state := quic.ConnectionState{SupportsDatagrams: true}
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockConnectionState: func() quic.ConnectionState {
|
MockConnectionState: func() quic.ConnectionState {
|
||||||
@ -225,9 +230,9 @@ func TestQUICEarlySessionConnectionState(t *testing.T) {
|
|||||||
if !reflect.DeepEqual(state, out) {
|
if !reflect.DeepEqual(state, out) {
|
||||||
t.Fatal("not the context we expected")
|
t.Fatal("not the context we expected")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionHandshakeComplete(t *testing.T) {
|
t.Run("HandshakeComplete", func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockHandshakeComplete: func() context.Context {
|
MockHandshakeComplete: func() context.Context {
|
||||||
@ -238,9 +243,9 @@ func TestQUICEarlySessionHandshakeComplete(t *testing.T) {
|
|||||||
if !reflect.DeepEqual(ctx, out) {
|
if !reflect.DeepEqual(ctx, out) {
|
||||||
t.Fatal("not the context we expected")
|
t.Fatal("not the context we expected")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionNextSession(t *testing.T) {
|
t.Run("NextSession", func(t *testing.T) {
|
||||||
next := &QUICEarlySession{}
|
next := &QUICEarlySession{}
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockNextSession: func() quic.Session {
|
MockNextSession: func() quic.Session {
|
||||||
@ -251,9 +256,9 @@ func TestQUICEarlySessionNextSession(t *testing.T) {
|
|||||||
if !reflect.DeepEqual(next, out) {
|
if !reflect.DeepEqual(next, out) {
|
||||||
t.Fatal("not the context we expected")
|
t.Fatal("not the context we expected")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionSendMessage(t *testing.T) {
|
t.Run("SendMessage", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockSendMessage: func(b []byte) error {
|
MockSendMessage: func(b []byte) error {
|
||||||
@ -265,9 +270,9 @@ func TestQUICEarlySessionSendMessage(t *testing.T) {
|
|||||||
if !errors.Is(err, expected) {
|
if !errors.Is(err, expected) {
|
||||||
t.Fatal("not the error we expected", err)
|
t.Fatal("not the error we expected", err)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICEarlySessionReceiveMessage(t *testing.T) {
|
t.Run("ReceiveMessage", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
sess := &QUICEarlySession{
|
sess := &QUICEarlySession{
|
||||||
MockReceiveMessage: func() ([]byte, error) {
|
MockReceiveMessage: func() ([]byte, error) {
|
||||||
@ -281,11 +286,13 @@ func TestQUICEarlySessionReceiveMessage(t *testing.T) {
|
|||||||
if b != nil {
|
if b != nil {
|
||||||
t.Fatal("expected nil buffer here")
|
t.Fatal("expected nil buffer here")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQUICUDPConnWriteTo(t *testing.T) {
|
func TestQUICUDPLikeConn(t *testing.T) {
|
||||||
|
t.Run("WriteTo", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
quc := &QUICUDPConn{
|
quc := &QUICUDPLikeConn{
|
||||||
MockWriteTo: func(p []byte, addr net.Addr) (int, error) {
|
MockWriteTo: func(p []byte, addr net.Addr) (int, error) {
|
||||||
return 0, expected
|
return 0, expected
|
||||||
},
|
},
|
||||||
@ -299,11 +306,11 @@ func TestQUICUDPConnWriteTo(t *testing.T) {
|
|||||||
if cnt != 0 {
|
if cnt != 0 {
|
||||||
t.Fatal("expected zero here")
|
t.Fatal("expected zero here")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICUDPConnClose(t *testing.T) {
|
t.Run("ConnClose", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
quc := &QUICUDPConn{
|
quc := &QUICUDPLikeConn{
|
||||||
MockClose: func() error {
|
MockClose: func() error {
|
||||||
return expected
|
return expected
|
||||||
},
|
},
|
||||||
@ -312,14 +319,14 @@ func TestQUICUDPConnClose(t *testing.T) {
|
|||||||
if !errors.Is(err, expected) {
|
if !errors.Is(err, expected) {
|
||||||
t.Fatal("not the error we expected", err)
|
t.Fatal("not the error we expected", err)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICUDPConnLocalAddrWorks(t *testing.T) {
|
t.Run("LocalAddr", func(t *testing.T) {
|
||||||
expected := &net.TCPAddr{
|
expected := &net.TCPAddr{
|
||||||
IP: net.IPv6loopback,
|
IP: net.IPv6loopback,
|
||||||
Port: 1234,
|
Port: 1234,
|
||||||
}
|
}
|
||||||
c := &QUICUDPConn{
|
c := &QUICUDPLikeConn{
|
||||||
MockLocalAddr: func() net.Addr {
|
MockLocalAddr: func() net.Addr {
|
||||||
return expected
|
return expected
|
||||||
},
|
},
|
||||||
@ -328,14 +335,14 @@ func TestQUICUDPConnLocalAddrWorks(t *testing.T) {
|
|||||||
if diff := cmp.Diff(expected, out); diff != "" {
|
if diff := cmp.Diff(expected, out); diff != "" {
|
||||||
t.Fatal(diff)
|
t.Fatal(diff)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICUDPConnRemoteAddrWorks(t *testing.T) {
|
t.Run("RemoteAddr", func(t *testing.T) {
|
||||||
expected := &net.TCPAddr{
|
expected := &net.TCPAddr{
|
||||||
IP: net.IPv6loopback,
|
IP: net.IPv6loopback,
|
||||||
Port: 1234,
|
Port: 1234,
|
||||||
}
|
}
|
||||||
c := &QUICUDPConn{
|
c := &QUICUDPLikeConn{
|
||||||
MockRemoteAddr: func() net.Addr {
|
MockRemoteAddr: func() net.Addr {
|
||||||
return expected
|
return expected
|
||||||
},
|
},
|
||||||
@ -344,11 +351,11 @@ func TestQUICUDPConnRemoteAddrWorks(t *testing.T) {
|
|||||||
if diff := cmp.Diff(expected, out); diff != "" {
|
if diff := cmp.Diff(expected, out); diff != "" {
|
||||||
t.Fatal(diff)
|
t.Fatal(diff)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICUDPConnSetDeadline(t *testing.T) {
|
t.Run("SetDeadline", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
c := &QUICUDPConn{
|
c := &QUICUDPLikeConn{
|
||||||
MockSetDeadline: func(t time.Time) error {
|
MockSetDeadline: func(t time.Time) error {
|
||||||
return expected
|
return expected
|
||||||
},
|
},
|
||||||
@ -357,11 +364,11 @@ func TestQUICUDPConnSetDeadline(t *testing.T) {
|
|||||||
if !errors.Is(err, expected) {
|
if !errors.Is(err, expected) {
|
||||||
t.Fatal("not the error we expected", err)
|
t.Fatal("not the error we expected", err)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICUDPConnSetReadDeadline(t *testing.T) {
|
t.Run("SetReadDeadline", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
c := &QUICUDPConn{
|
c := &QUICUDPLikeConn{
|
||||||
MockSetReadDeadline: func(t time.Time) error {
|
MockSetReadDeadline: func(t time.Time) error {
|
||||||
return expected
|
return expected
|
||||||
},
|
},
|
||||||
@ -370,11 +377,11 @@ func TestQUICUDPConnSetReadDeadline(t *testing.T) {
|
|||||||
if !errors.Is(err, expected) {
|
if !errors.Is(err, expected) {
|
||||||
t.Fatal("not the error we expected", err)
|
t.Fatal("not the error we expected", err)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICUDPConnSetWriteDeadline(t *testing.T) {
|
t.Run("SetWriteDeadline", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
c := &QUICUDPConn{
|
c := &QUICUDPLikeConn{
|
||||||
MockSetWriteDeadline: func(t time.Time) error {
|
MockSetWriteDeadline: func(t time.Time) error {
|
||||||
return expected
|
return expected
|
||||||
},
|
},
|
||||||
@ -383,11 +390,11 @@ func TestQUICUDPConnSetWriteDeadline(t *testing.T) {
|
|||||||
if !errors.Is(err, expected) {
|
if !errors.Is(err, expected) {
|
||||||
t.Fatal("not the error we expected", err)
|
t.Fatal("not the error we expected", err)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICUDPConnReadFrom(t *testing.T) {
|
t.Run("ConnReadFrom", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
quc := &QUICUDPConn{
|
quc := &QUICUDPLikeConn{
|
||||||
MockReadFrom: func(b []byte) (int, net.Addr, error) {
|
MockReadFrom: func(b []byte) (int, net.Addr, error) {
|
||||||
return 0, nil, expected
|
return 0, nil, expected
|
||||||
},
|
},
|
||||||
@ -403,11 +410,11 @@ func TestQUICUDPConnReadFrom(t *testing.T) {
|
|||||||
if addr != nil {
|
if addr != nil {
|
||||||
t.Fatal("expected nil here")
|
t.Fatal("expected nil here")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICUDPConnSyscallConn(t *testing.T) {
|
t.Run("SyscallConn", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
quc := &QUICUDPConn{
|
quc := &QUICUDPLikeConn{
|
||||||
MockSyscallConn: func() (syscall.RawConn, error) {
|
MockSyscallConn: func() (syscall.RawConn, error) {
|
||||||
return nil, expected
|
return nil, expected
|
||||||
},
|
},
|
||||||
@ -419,11 +426,11 @@ func TestQUICUDPConnSyscallConn(t *testing.T) {
|
|||||||
if conn != nil {
|
if conn != nil {
|
||||||
t.Fatal("expected nil here")
|
t.Fatal("expected nil here")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestQUICUDPConnSetReadBuffer(t *testing.T) {
|
t.Run("SetReadBuffer", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
quc := &QUICUDPConn{
|
quc := &QUICUDPLikeConn{
|
||||||
MockSetReadBuffer: func(n int) error {
|
MockSetReadBuffer: func(n int) error {
|
||||||
return expected
|
return expected
|
||||||
},
|
},
|
||||||
@ -432,4 +439,5 @@ func TestQUICUDPConnSetReadBuffer(t *testing.T) {
|
|||||||
if !errors.Is(err, expected) {
|
if !errors.Is(err, expected) {
|
||||||
t.Fatal("not the error we expected", err)
|
t.Fatal("not the error we expected", err)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReaderRead(t *testing.T) {
|
func TestReader(t *testing.T) {
|
||||||
|
t.Run("Read", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
r := &Reader{
|
r := &Reader{
|
||||||
MockRead: func(b []byte) (int, error) {
|
MockRead: func(b []byte) (int, error) {
|
||||||
@ -20,4 +21,5 @@ func TestReaderRead(t *testing.T) {
|
|||||||
if count != 0 {
|
if count != 0 {
|
||||||
t.Fatal("unexpected count", count)
|
t.Fatal("unexpected count", count)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResolverLookupHost(t *testing.T) {
|
func TestResolver(t *testing.T) {
|
||||||
|
t.Run("LookupHost", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
r := &Resolver{
|
r := &Resolver{
|
||||||
MockLookupHost: func(ctx context.Context, domain string) ([]string, error) {
|
MockLookupHost: func(ctx context.Context, domain string) ([]string, error) {
|
||||||
@ -21,9 +22,9 @@ func TestResolverLookupHost(t *testing.T) {
|
|||||||
if addrs != nil {
|
if addrs != nil {
|
||||||
t.Fatal("expected nil addr")
|
t.Fatal("expected nil addr")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestResolverNetwork(t *testing.T) {
|
t.Run("Network", func(t *testing.T) {
|
||||||
r := &Resolver{
|
r := &Resolver{
|
||||||
MockNetwork: func() string {
|
MockNetwork: func() string {
|
||||||
return "antani"
|
return "antani"
|
||||||
@ -32,9 +33,9 @@ func TestResolverNetwork(t *testing.T) {
|
|||||||
if v := r.Network(); v != "antani" {
|
if v := r.Network(); v != "antani" {
|
||||||
t.Fatal("unexpected network", v)
|
t.Fatal("unexpected network", v)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestResolverAddress(t *testing.T) {
|
t.Run("Address", func(t *testing.T) {
|
||||||
r := &Resolver{
|
r := &Resolver{
|
||||||
MockAddress: func() string {
|
MockAddress: func() string {
|
||||||
return "1.1.1.1"
|
return "1.1.1.1"
|
||||||
@ -43,9 +44,9 @@ func TestResolverAddress(t *testing.T) {
|
|||||||
if v := r.Address(); v != "1.1.1.1" {
|
if v := r.Address(); v != "1.1.1.1" {
|
||||||
t.Fatal("unexpected address", v)
|
t.Fatal("unexpected address", v)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestResolverCloseIdleConnections(t *testing.T) {
|
t.Run("CloseIdleConnections", func(t *testing.T) {
|
||||||
var called bool
|
var called bool
|
||||||
r := &Resolver{
|
r := &Resolver{
|
||||||
MockCloseIdleConnections: func() {
|
MockCloseIdleConnections: func() {
|
||||||
@ -56,4 +57,5 @@ func TestResolverCloseIdleConnections(t *testing.T) {
|
|||||||
if !called {
|
if !called {
|
||||||
t.Fatal("not called")
|
t.Fatal("not called")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTLSHandshakerHandshake(t *testing.T) {
|
func TestTLSHandshaker(t *testing.T) {
|
||||||
|
t.Run("Handshake", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
conn := &Conn{}
|
conn := &Conn{}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@ -30,9 +31,11 @@ func TestTLSHandshakerHandshake(t *testing.T) {
|
|||||||
if tlsConn != nil {
|
if tlsConn != nil {
|
||||||
t.Fatal("expected nil conn here")
|
t.Fatal("expected nil conn here")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTLSConnConnectionState(t *testing.T) {
|
func TestTLSConn(t *testing.T) {
|
||||||
|
t.Run("ConnectionState", func(t *testing.T) {
|
||||||
state := tls.ConnectionState{Version: tls.VersionTLS12}
|
state := tls.ConnectionState{Version: tls.VersionTLS12}
|
||||||
c := &TLSConn{
|
c := &TLSConn{
|
||||||
MockConnectionState: func() tls.ConnectionState {
|
MockConnectionState: func() tls.ConnectionState {
|
||||||
@ -43,9 +46,9 @@ func TestTLSConnConnectionState(t *testing.T) {
|
|||||||
if !reflect.DeepEqual(out, state) {
|
if !reflect.DeepEqual(out, state) {
|
||||||
t.Fatal("not the result we expected")
|
t.Fatal("not the result we expected")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestTLSConnHandshakeContext(t *testing.T) {
|
t.Run("HandshakeContext", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
c := &TLSConn{
|
c := &TLSConn{
|
||||||
MockHandshakeContext: func(ctx context.Context) error {
|
MockHandshakeContext: func(ctx context.Context) error {
|
||||||
@ -56,9 +59,11 @@ func TestTLSConnHandshakeContext(t *testing.T) {
|
|||||||
if !errors.Is(err, expected) {
|
if !errors.Is(err, expected) {
|
||||||
t.Fatal("not the error we expected", err)
|
t.Fatal("not the error we expected", err)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTLSDialerCloseIdleConnections(t *testing.T) {
|
func TestTLSDialer(t *testing.T) {
|
||||||
|
t.Run("CloseIdleConnections", func(t *testing.T) {
|
||||||
var called bool
|
var called bool
|
||||||
td := &TLSDialer{
|
td := &TLSDialer{
|
||||||
MockCloseIdleConnections: func() {
|
MockCloseIdleConnections: func() {
|
||||||
@ -69,9 +74,9 @@ func TestTLSDialerCloseIdleConnections(t *testing.T) {
|
|||||||
if !called {
|
if !called {
|
||||||
t.Fatal("not called")
|
t.Fatal("not called")
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestTLSDialerDialTLSContext(t *testing.T) {
|
t.Run("DialTLSContext", func(t *testing.T) {
|
||||||
expected := errors.New("mocked error")
|
expected := errors.New("mocked error")
|
||||||
td := &TLSDialer{
|
td := &TLSDialer{
|
||||||
MockDialTLSContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
MockDialTLSContext: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
@ -86,4 +91,5 @@ func TestTLSDialerDialTLSContext(t *testing.T) {
|
|||||||
if conn != nil {
|
if conn != nil {
|
||||||
t.Fatal("expected nil conn here")
|
t.Fatal("expected nil conn here")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -493,7 +493,7 @@ func TestNewSingleUseQUICDialerWorksAsIntended(t *testing.T) {
|
|||||||
func TestQUICListenerErrWrapper(t *testing.T) {
|
func TestQUICListenerErrWrapper(t *testing.T) {
|
||||||
t.Run("Listen", func(t *testing.T) {
|
t.Run("Listen", func(t *testing.T) {
|
||||||
t.Run("on success", func(t *testing.T) {
|
t.Run("on success", func(t *testing.T) {
|
||||||
expectedConn := &mocks.QUICUDPConn{}
|
expectedConn := &mocks.QUICUDPLikeConn{}
|
||||||
ql := &quicListenerErrWrapper{
|
ql := &quicListenerErrWrapper{
|
||||||
QUICListener: &mocks.QUICListener{
|
QUICListener: &mocks.QUICListener{
|
||||||
MockListen: func(addr *net.UDPAddr) (quicx.UDPLikeConn, error) {
|
MockListen: func(addr *net.UDPAddr) (quicx.UDPLikeConn, error) {
|
||||||
@ -537,7 +537,7 @@ func TestQUICErrWrapperUDPLikeConn(t *testing.T) {
|
|||||||
expectedAddr := &net.UDPAddr{}
|
expectedAddr := &net.UDPAddr{}
|
||||||
p := make([]byte, 128)
|
p := make([]byte, 128)
|
||||||
conn := &quicErrWrapperUDPLikeConn{
|
conn := &quicErrWrapperUDPLikeConn{
|
||||||
UDPLikeConn: &mocks.QUICUDPConn{
|
UDPLikeConn: &mocks.QUICUDPLikeConn{
|
||||||
MockReadFrom: func(p []byte) (n int, addr net.Addr, err error) {
|
MockReadFrom: func(p []byte) (n int, addr net.Addr, err error) {
|
||||||
return len(p), expectedAddr, nil
|
return len(p), expectedAddr, nil
|
||||||
},
|
},
|
||||||
@ -559,7 +559,7 @@ func TestQUICErrWrapperUDPLikeConn(t *testing.T) {
|
|||||||
p := make([]byte, 128)
|
p := make([]byte, 128)
|
||||||
expectedErr := io.EOF
|
expectedErr := io.EOF
|
||||||
conn := &quicErrWrapperUDPLikeConn{
|
conn := &quicErrWrapperUDPLikeConn{
|
||||||
UDPLikeConn: &mocks.QUICUDPConn{
|
UDPLikeConn: &mocks.QUICUDPLikeConn{
|
||||||
MockReadFrom: func(p []byte) (n int, addr net.Addr, err error) {
|
MockReadFrom: func(p []byte) (n int, addr net.Addr, err error) {
|
||||||
return 0, nil, expectedErr
|
return 0, nil, expectedErr
|
||||||
},
|
},
|
||||||
@ -582,7 +582,7 @@ func TestQUICErrWrapperUDPLikeConn(t *testing.T) {
|
|||||||
t.Run("on success", func(t *testing.T) {
|
t.Run("on success", func(t *testing.T) {
|
||||||
p := make([]byte, 128)
|
p := make([]byte, 128)
|
||||||
conn := &quicErrWrapperUDPLikeConn{
|
conn := &quicErrWrapperUDPLikeConn{
|
||||||
UDPLikeConn: &mocks.QUICUDPConn{
|
UDPLikeConn: &mocks.QUICUDPLikeConn{
|
||||||
MockWriteTo: func(p []byte, addr net.Addr) (int, error) {
|
MockWriteTo: func(p []byte, addr net.Addr) (int, error) {
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
},
|
},
|
||||||
@ -601,7 +601,7 @@ func TestQUICErrWrapperUDPLikeConn(t *testing.T) {
|
|||||||
p := make([]byte, 128)
|
p := make([]byte, 128)
|
||||||
expectedErr := io.EOF
|
expectedErr := io.EOF
|
||||||
conn := &quicErrWrapperUDPLikeConn{
|
conn := &quicErrWrapperUDPLikeConn{
|
||||||
UDPLikeConn: &mocks.QUICUDPConn{
|
UDPLikeConn: &mocks.QUICUDPLikeConn{
|
||||||
MockWriteTo: func(p []byte, addr net.Addr) (int, error) {
|
MockWriteTo: func(p []byte, addr net.Addr) (int, error) {
|
||||||
return 0, expectedErr
|
return 0, expectedErr
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user