-
Notifications
You must be signed in to change notification settings - Fork 0
/
router_options_test.go
63 lines (50 loc) · 1.21 KB
/
router_options_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
package stargate
import (
"net/http/httptest"
"testing"
)
func TestWithLoadBalancer(t *testing.T) {
lister := newLister([]*httptest.Server{}, "http")
tests := []struct {
name string
maker LoadBalancerMaker
value string
}{
{"no balancer maker should default to RoundRobin", nil, "Stargate/RoundRobin"},
{"check RoundRobin", RoundRobin, "Stargate/RoundRobin"},
}
for _, tc := range tests {
t.Logf("running test %q", tc.name)
var (
router *Router
err error
)
if tc.maker != nil {
router, err = NewRouter(lister, WithLoadBalancer(tc.maker))
} else {
router, err = NewRouter(lister)
}
if err != nil {
t.Fatalf("cannot create stargate proxy: %v", err)
}
rs, err := lister.List("/")
if err != nil {
t.Fatalf("cannot query routes: %v", err)
}
servers := make([]OriginServer, 0)
for _, options := range rs {
server, err := NewOriginServer(options, defaultDirector("/"))
if err != nil {
t.Fatal(err)
}
servers = append(servers, server)
}
lb, err := router.loadBalancerMaker(servers)
if err != nil {
t.Fatalf("cannot create lb: %v", err)
}
if lb.Name() != tc.value {
t.Fatalf("expected %q load balancer, got %q", tc.value, lb.Name())
}
}
}