This repository has been archived by the owner on Jul 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
consul_test.go
68 lines (56 loc) · 2.04 KB
/
consul_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
package consul
import (
"testing"
"github.com/hashicorp/consul/api"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)
var _ = Describe("Consul", func() {
var (
s1 = &api.AgentService{Tags: []string{"a", "b", "c", "d"}, Port: 8080}
s2 = &api.AgentService{Tags: []string{"c", "d", "e", "f"}, Port: 8080}
s3 = &api.AgentService{Tags: []string{"a", "b", "c", "d"}, Port: 8080, Address: "10.1.1.1"}
)
var (
n1 = &api.ServiceEntry{Node: &api.Node{Address: "10.0.0.1"}, Service: s1}
n2 = &api.ServiceEntry{Node: &api.Node{Address: "10.0.0.2"}, Service: s2}
n3 = &api.ServiceEntry{Node: &api.Node{Address: "10.0.0.3"}, Service: s1}
n4 = &api.ServiceEntry{Node: &api.Node{Address: "10.0.0.4"}, Service: s3}
n5 = &api.ServiceEntry{Node: &api.Node{Address: "10.0.0.5"}, Service: s1}
)
DescribeTable("splitTarget",
func(target, service string, tags []string) {
svc, tags := splitTarget(target)
Expect(svc).To(Equal(service))
Expect(tags).To(Equal(tags))
},
Entry("no tags", "svcname", "svcname", nil),
Entry("one tag", "svcname,tag", "svcname", []string{"tag"}),
Entry("two tags", "svcname,a,b", "svcname", []string{"a", "b"}),
)
It("should parse entries", func() {
addrs := parseEntries([]*api.ServiceEntry{n1, n2, n3, n4, n5})
Expect(addrs).To(Equal([]string{
"10.0.0.1:8080",
"10.0.0.2:8080",
"10.0.0.3:8080",
"10.1.1.1:8080",
"10.0.0.5:8080",
}))
})
It("should filter entries", func() {
entries := filterEntries([]*api.ServiceEntry{n1, n2, n3, n4, n5}, []string{"b", "c", "d"})
Expect(entries).To(HaveLen(4))
entries = filterEntries([]*api.ServiceEntry{n1, n2, n3, n4, n5}, []string{"e", "c", "d"})
Expect(entries).To(HaveLen(1))
entries = filterEntries([]*api.ServiceEntry{n1, n2, n3, n4, n5}, []string{})
Expect(entries).To(HaveLen(5))
entries = filterEntries([]*api.ServiceEntry{n1, n2, n3, n4, n5}, nil)
Expect(entries).To(HaveLen(5))
})
})
func TestSuite(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "grpclb/discovery/consul")
}