forked from kubernetes-sigs/controller-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager_test.go
61 lines (49 loc) · 1.59 KB
/
manager_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package addr_test
import (
"net"
"strconv"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"sigs.k8s.io/controller-runtime/pkg/internal/testing/addr"
)
var _ = Describe("SuggestAddress", func() {
It("returns a free port and an address to bind to", func() {
port, host, err := addr.Suggest("")
Expect(err).NotTo(HaveOccurred())
Expect(host).To(Or(Equal("127.0.0.1"), Equal("::1")))
Expect(port).NotTo(Equal(0))
addr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(host, strconv.Itoa(port)))
Expect(err).NotTo(HaveOccurred())
l, err := net.ListenTCP("tcp", addr)
defer func() {
Expect(l.Close()).To(Succeed())
}()
Expect(err).NotTo(HaveOccurred())
})
It("supports an explicit listenHost", func() {
port, host, err := addr.Suggest("localhost")
Expect(err).NotTo(HaveOccurred())
Expect(host).To(Or(Equal("127.0.0.1"), Equal("::1")))
Expect(port).NotTo(Equal(0))
addr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(host, strconv.Itoa(port)))
Expect(err).NotTo(HaveOccurred())
l, err := net.ListenTCP("tcp", addr)
defer func() {
Expect(l.Close()).To(Succeed())
}()
Expect(err).NotTo(HaveOccurred())
})
It("supports a 0.0.0.0 listenHost", func() {
port, host, err := addr.Suggest("0.0.0.0")
Expect(err).NotTo(HaveOccurred())
Expect(host).To(Equal("0.0.0.0"))
Expect(port).NotTo(Equal(0))
addr, err := net.ResolveTCPAddr("tcp", net.JoinHostPort(host, strconv.Itoa(port)))
Expect(err).NotTo(HaveOccurred())
l, err := net.ListenTCP("tcp", addr)
defer func() {
Expect(l.Close()).To(Succeed())
}()
Expect(err).NotTo(HaveOccurred())
})
})