-
Notifications
You must be signed in to change notification settings - Fork 15
/
dial_test.go
41 lines (36 loc) · 1.01 KB
/
dial_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
package quicconn
import (
"crypto/tls"
"errors"
"net"
quic "github.com/lucas-clemente/quic-go"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Dial and Listen", func() {
AfterEach(func() {
quicListen = quic.Listen
})
It("listens", func() {
var conn net.PacketConn
var tlsConfig *tls.Config
tlsConf := &tls.Config{}
quicListen = func(c net.PacketConn, tlsConf *tls.Config, _ *quic.Config) (quic.Listener, error) {
conn = c
tlsConfig = tlsConf
return nil, nil
}
_, err := Listen("udp", "localhost:12345", tlsConf)
Expect(err).ToNot(HaveOccurred())
Expect(conn.(*net.UDPConn).LocalAddr().String()).To(Equal("127.0.0.1:12345"))
Expect(tlsConfig).To(Equal(tlsConf))
})
It("returns listen errors", func() {
testErr := errors.New("listen error")
quicListen = func(_ net.PacketConn, _ *tls.Config, _ *quic.Config) (quic.Listener, error) {
return nil, testErr
}
_, err := Listen("udp", "localhost:12346", &tls.Config{})
Expect(err).To(MatchError(testErr))
})
})