This repository has been archived by the owner on Feb 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
servers_test.go
90 lines (76 loc) · 1.86 KB
/
servers_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 srvcache
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestChoria(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Choria SRV Cache")
}
var _ = Describe("Servers", func() {
var s *servers
BeforeEach(func() {
s = &servers{servers: []Server{NewServer("h1", 8080, "http"), NewServer("h2", 8080, "https")}}
})
Describe("Count", func() {
It("Should store the supplied servers", func() {
Expect(s.servers).To(HaveLen(2))
Expect(s.Count()).To(Equal(2))
})
})
Describe("Servers", func() {
It("Should return the stored servers", func() {
srvs := s.Servers()
Expect(srvs).To(HaveLen(2))
Expect(srvs[0].Host()).To(Equal("h1"))
Expect(srvs[1].Host()).To(Equal("h2"))
})
})
Describe("Each", func() {
It("Should yield all instances and allow edits", func() {
s.Each(func(srv Server) {
srv.SetHost("test" + srv.Host())
})
hps := s.HostPorts()
Expect(hps).To(Equal([]string{
"testh1:8080",
"testh2:8080",
}))
})
It("Should correctly handle empty collections", func() {
s = &servers{[]Server{}}
called := false
s.Each(func(srv Server) {
called = true
})
Expect(called).To(BeFalse())
})
})
Describe("Strings", func() {
It("Should return the right strings", func() {
Expect(s.Strings()).To(Equal([]string{
"http://h1:8080",
"https://h2:8080",
}))
})
})
Describe("URLs", func() {
It("Should produce correct URLs", func() {
urls, err := s.URLs()
Expect(err).ToNot(HaveOccurred())
Expect(urls[0].Host).To(Equal("h1:8080"))
Expect(urls[0].Scheme).To(Equal("http"))
Expect(urls[1].Host).To(Equal("h2:8080"))
Expect(urls[1].Scheme).To(Equal("https"))
})
})
Describe("HostPorts", func() {
It("Should produce correct hps", func() {
Expect(s.HostPorts()).To(Equal([]string{
"h1:8080",
"h2:8080",
}))
})
})
})