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

     1  package quic
     2  
     3  import (
     4  	"net"
     5  
     6  	. "github.com/onsi/ginkgo/v2"
     7  	. "github.com/onsi/gomega"
     8  )
     9  
    10  var _ = Describe("Connection (for sending packets)", func() {
    11  	var (
    12  		c          sendConn
    13  		packetConn *MockPacketConn
    14  		addr       net.Addr
    15  	)
    16  
    17  	BeforeEach(func() {
    18  		addr = &net.UDPAddr{IP: net.IPv4(192, 168, 100, 200), Port: 1337}
    19  		packetConn = NewMockPacketConn(mockCtrl)
    20  		rawConn, err := wrapConn(packetConn)
    21  		Expect(err).ToNot(HaveOccurred())
    22  		c = newSendConnWithPacketInfo(rawConn, addr, packetInfo{})
    23  	})
    24  
    25  	It("writes", func() {
    26  		packetConn.EXPECT().WriteTo([]byte("foobar"), addr)
    27  		Expect(c.Write([]byte("foobar"), 6)).To(Succeed())
    28  	})
    29  
    30  	It("gets the remote address", func() {
    31  		Expect(c.RemoteAddr().String()).To(Equal("192.168.100.200:1337"))
    32  	})
    33  
    34  	It("gets the local address", func() {
    35  		addr := &net.UDPAddr{
    36  			IP:   net.IPv4(192, 168, 0, 1),
    37  			Port: 1234,
    38  		}
    39  		packetConn.EXPECT().LocalAddr().Return(addr)
    40  		Expect(c.LocalAddr()).To(Equal(addr))
    41  	})
    42  
    43  	It("closes", func() {
    44  		packetConn.EXPECT().Close()
    45  		Expect(c.Close()).To(Succeed())
    46  	})
    47  })