-
Notifications
You must be signed in to change notification settings - Fork 17
/
server_test.go
78 lines (61 loc) · 2.06 KB
/
server_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
package delta
import (
. "github.com/r7kamura/gospel"
"net/http"
"testing"
)
func TestServer(t *testing.T) {
Describe(t, "NewServer", func() {
server := NewServer("0.0.0.0", 8484)
It("should set host into its Host field", func() {
Expect(server.Host).To(Equal, "0.0.0.0")
})
It("should set port into its Port field", func() {
Expect(server.Port).To(Equal, 8484)
})
It("should set a handler to select backend by default", func() {
Expect(server.onSelectBackendHandler).To(Exist)
})
})
Describe(t, "AddMasterBackend", func() {
server := NewServer("0.0.0.0", 8484)
It("should set a backend as a master", func() {
count := len(server.Backends)
server.AddMasterBackend("master", "127.0.01", 8080)
Expect(server.Backends["master"].IsMaster).To(Equal, true)
Expect(len(server.Backends)).To(Equal, count+1)
})
})
Describe(t, "AddBackend", func() {
server := NewServer("0.0.0.0", 8484)
It("should set a backend as a testing server", func() {
count := len(server.Backends)
server.AddBackend("testing", "127.0.01", 8081)
Expect(server.Backends["testing"].IsMaster).To(Equal, false)
Expect(len(server.Backends)).To(Equal, count+1)
})
})
Describe(t, "OnSelectBackend", func() {
server := NewServer("0.0.0.0", 8484)
It("should set a handler into its onSelectBackendHandler field", func() {
server.OnSelectBackend(func(req *http.Request) []string {
return []string{"testing"}
})
Expect(server.onSelectBackendHandler).To(NotEqual, nil)
})
})
Describe(t, "OnMungeHeader", func() {
server := NewServer("0.0.0.0", 8484)
It("should set a handler into its onMungeHeaderHandler field", func() {
server.OnMungeHeader(func(backend string, header *http.Header) {})
Expect(server.onMungeHeaderHandler).To(Exist)
})
})
Describe(t, "OnBackendFinished", func() {
server := NewServer("0.0.0.0", 8484)
It("should set a handler into its onBackendFinishedHandler field", func() {
server.OnBackendFinished(func(responses map[string]*Response) {})
Expect(server.onBackendFinishedHandler).To(Exist)
})
})
}