transport_test.go 1.24 KB
Newer Older
Marten Seemann's avatar
Marten Seemann committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package libp2pquic

import (
	ma "github.com/multiformats/go-multiaddr"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Transport", func() {
	var t *QuicTransport

	BeforeEach(func() {
		t = NewQuicTransport(nil)
	})

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
	Context("listening", func() {
		It("creates a new listener", func() {
			maddr, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/1234/quic")
			Expect(err).ToNot(HaveOccurred())
			ln, err := t.Listen(maddr)
			Expect(err).ToNot(HaveOccurred())
			Expect(ln.Multiaddr()).To(Equal(maddr))
		})

		It("returns an existing listener", func() {
			maddr, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/1235/quic")
			Expect(err).ToNot(HaveOccurred())
			ln, err := t.Listen(maddr)
			Expect(err).ToNot(HaveOccurred())
			Expect(ln.Multiaddr()).To(Equal(maddr))
			ln2, err := t.Listen(maddr)
			Expect(err).ToNot(HaveOccurred())
			Expect(ln2).To(Equal(ln))
			Expect(t.listeners).To(HaveLen(1))
		})
	})

Marten Seemann's avatar
Marten Seemann committed
39
40
41
42
43
44
45
46
47
	It("matches", func() {
		invalidAddr, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/1234")
		Expect(err).ToNot(HaveOccurred())
		validAddr, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/1234/quic")
		Expect(err).ToNot(HaveOccurred())
		Expect(t.Matches(invalidAddr)).To(BeFalse())
		Expect(t.Matches(validAddr)).To(BeTrue())
	})
})