github.com/tumi8/quic-go@v0.37.4-tum/sys_conn_test.go (about)

     1  package quic
     2  
     3  import (
     4  	"net"
     5  	"time"
     6  
     7  	"github.com/tumi8/quic-go/noninternal/protocol"
     8  
     9  	"github.com/golang/mock/gomock"
    10  
    11  	. "github.com/onsi/ginkgo/v2"
    12  	. "github.com/onsi/gomega"
    13  )
    14  
    15  var _ = Describe("Basic Conn Test", func() {
    16  	It("reads a packet", func() {
    17  		c := NewMockPacketConn(mockCtrl)
    18  		addr := &net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 1234}
    19  		c.EXPECT().ReadFrom(gomock.Any()).DoAndReturn(func(b []byte) (int, net.Addr, error) {
    20  			data := []byte("foobar")
    21  			Expect(b).To(HaveLen(protocol.MaxPacketBufferSize))
    22  			return copy(b, data), addr, nil
    23  		})
    24  
    25  		conn, err := wrapConn(c)
    26  		Expect(err).ToNot(HaveOccurred())
    27  		p, err := conn.ReadPacket()
    28  		Expect(err).ToNot(HaveOccurred())
    29  		Expect(p.data).To(Equal([]byte("foobar")))
    30  		Expect(p.rcvTime).To(BeTemporally("~", time.Now(), scaleDuration(100*time.Millisecond)))
    31  		Expect(p.remoteAddr).To(Equal(addr))
    32  	})
    33  })