Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Dec 13, 2023
1 parent 907d1e9 commit 03401d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions internal/mocks/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ type QUICEarlyConnection struct {
MockConnectionState func() quic.ConnectionState
MockHandshakeComplete func() <-chan struct{}
MockNextConnection func() quic.Connection
MockSendMessage func(b []byte) error
MockReceiveMessage func(ctx context.Context) ([]byte, error)
MockSendDatagram func(b []byte) error
MockReceiveDatagram func(ctx context.Context) ([]byte, error)
}

var _ quic.EarlyConnection = &QUICEarlyConnection{}
Expand Down Expand Up @@ -121,14 +121,14 @@ func (s *QUICEarlyConnection) NextConnection() quic.Connection {
return s.MockNextConnection()
}

// SendMessage calls MockSendMessage.
func (s *QUICEarlyConnection) SendMessage(b []byte) error {
return s.MockSendMessage(b)
// SendDatagram calls MockSendDatagram.
func (s *QUICEarlyConnection) SendDatagram(b []byte) error {
return s.MockSendDatagram(b)
}

// ReceiveMessage calls MockReceiveMessage.
func (s *QUICEarlyConnection) ReceiveMessage(ctx context.Context) ([]byte, error) {
return s.MockReceiveMessage(ctx)
// ReceiveDatagram calls MockReceiveDatagram.
func (s *QUICEarlyConnection) ReceiveDatagram(ctx context.Context) ([]byte, error) {
return s.MockReceiveDatagram(ctx)
}

// UDPLikeConn is an UDP conn used by QUIC.
Expand Down
12 changes: 6 additions & 6 deletions internal/mocks/quic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,29 +239,29 @@ func TestQUICEarlyConnection(t *testing.T) {
}
})

t.Run("SendMessage", func(t *testing.T) {
t.Run("SendDatagram", func(t *testing.T) {
expected := errors.New("mocked error")
qconn := &QUICEarlyConnection{
MockSendMessage: func(b []byte) error {
MockSendDatagram: func(b []byte) error {
return expected
},
}
b := make([]byte, 17)
err := qconn.SendMessage(b)
err := qconn.SendDatagram(b)
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
})

t.Run("ReceiveMessage", func(t *testing.T) {
t.Run("ReceiveDatagram", func(t *testing.T) {
expected := errors.New("mocked error")
ctx := context.Background()
qconn := &QUICEarlyConnection{
MockReceiveMessage: func(ctx context.Context) ([]byte, error) {
MockReceiveDatagram: func(ctx context.Context) ([]byte, error) {
return nil, expected
},
}
b, err := qconn.ReceiveMessage(ctx)
b, err := qconn.ReceiveDatagram(ctx)
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
Expand Down

0 comments on commit 03401d8

Please sign in to comment.