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