-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver_test.go
More file actions
77 lines (73 loc) · 1.64 KB
/
server_test.go
File metadata and controls
77 lines (73 loc) · 1.64 KB
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
package server
import (
"github.com/microbay/microbay/model"
"testing"
)
func generateTestModel() []*model.Resource {
resources := make([]*model.Resource, 2)
micros := make([]model.Micro, 5)
micros[0] = model.Micro{"http://localhost:9000", 1}
micros[1] = model.Micro{"http://localhost:9001", 33}
micros[2] = model.Micro{"http://localhost:9002", 2}
micros[3] = model.Micro{"http://localhost:9003", 17}
micros[4] = model.Micro{"http://localhost:9004", 40}
resources[0] = &model.Resource{
Micros: micros,
}
micros = make([]model.Micro, 2)
micros[0] = model.Micro{"http://localhost:9000", 0}
micros[1] = model.Micro{"http://localhost:9001", 1000}
resources[1] = &model.Resource{
Micros: micros,
}
return resources
}
func TestBootstrapLoadBalancer(t *testing.T) {
resources := generateTestModel()
bootstrapLoadBalancer(resources)
resource := resources[0]
if resource.Backends == nil {
t.Error(
"expected", "instance of backend.Backends",
"got", nil,
)
t.FailNow()
}
if resource.Backends.Len() != 93 {
t.Error(
"expected", 93,
"got", resource.Backends.Len(),
)
t.FailNow()
}
resource = resources[1]
if resource.Backends == nil {
t.Error(
"expected", "instance of backend.Backends",
"got", nil,
)
t.FailNow()
}
if resource.Backends.Len() != 1000 {
t.Error(
"expected", 1000,
"got", resource.Backends.Len(),
)
t.FailNow()
}
b := resource.Backends
i := 0
for e := b.Choose(); e != nil; e = b.Choose() {
if i > 1001 {
break
}
if e.String() == "http://localhost:9000" {
t.Error(
"expected", "http://localhost:9001",
"got", "http://localhost:9000",
)
t.FailNow()
}
i++
}
}