/
template_v3_test.go
90 lines (70 loc) 路 2.12 KB
/
template_v3_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package bootstrap
import (
"errors"
"net"
envoy_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("dnsLookupFamilyFromXdsHost", func() {
It("should return AUTO when IPv6 found", func() {
// given
lookupFn := func(host string) ([]net.IP, error) {
return []net.IP{net.IPv6loopback}, nil
}
// when
result := dnsLookupFamilyFromXdsHost("example.com", lookupFn)
// then
Expect(result).To(Equal(envoy_cluster_v3.Cluster_AUTO))
})
It("should return AUTO for localhost", func() {
// given
lookupFn := func(host string) ([]net.IP, error) {
return []net.IP{net.IPv4(127, 0, 0, 1)}, nil
}
// when
result := dnsLookupFamilyFromXdsHost("localhost", lookupFn)
// then
Expect(result).To(Equal(envoy_cluster_v3.Cluster_AUTO))
})
It("should return AUTO when both IPv6 and IPv4 found", func() {
// given
lookupFn := func(host string) ([]net.IP, error) {
return []net.IP{net.IPv6loopback, net.IPv4(127, 0, 0, 1)}, nil
}
// when
result := dnsLookupFamilyFromXdsHost("example.com", lookupFn)
// then
Expect(result).To(Equal(envoy_cluster_v3.Cluster_AUTO))
})
It("should return IPV4 when only IPv4 found", func() {
// given
lookupFn := func(host string) ([]net.IP, error) {
return []net.IP{net.IPv4(127, 0, 0, 1)}, nil
}
// when
result := dnsLookupFamilyFromXdsHost("example.com", lookupFn)
// then
Expect(result).To(Equal(envoy_cluster_v3.Cluster_V4_ONLY))
})
It("should return AUTO (default) when no ips returned", func() {
// given
lookupFn := func(host string) ([]net.IP, error) {
return []net.IP{}, nil
}
// when
result := dnsLookupFamilyFromXdsHost("example.com", lookupFn)
// then
Expect(result).To(Equal(envoy_cluster_v3.Cluster_AUTO))
})
It("should return AUTO when error occurs", func() {
// given
lookupFn := func(host string) ([]net.IP, error) {
return nil, errors.New("could not resolve hostname")
}
// when
result := dnsLookupFamilyFromXdsHost("example.com", lookupFn)
// then
Expect(result).To(Equal(envoy_cluster_v3.Cluster_AUTO))
})
})