-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash_test.go
69 lines (67 loc) · 1.15 KB
/
hash_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
package balancer
import (
"reflect"
"testing"
)
func TestHash_SelectNode(t *testing.T) {
type args struct {
balancer *Balancer
clientID string
}
tests := []struct {
name string
h *Hash
args args
want Node
}{
{
name: "same node when we have only 1 node",
h: &Hash{},
args: args{
balancer: &Balancer{
UpstreamPool: []Node{
&MockNode{
nodeID: "127.0.0.1",
healthy: true,
},
},
},
},
want: &MockNode{
nodeID: "127.0.0.1",
healthy: true,
},
},
{
name: "empty upstreams should return nil",
h: &Hash{},
args: args{
balancer: &Balancer{
UpstreamPool: []Node{},
},
},
want: nil,
},
{
name: "no healthy upstream? then nil",
h: &Hash{},
args: args{
balancer: &Balancer{
UpstreamPool: []Node{
&MockNode{
healthy: false,
},
},
},
},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.h.SelectNode(tt.args.balancer, tt.args.clientID); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Hash.SelectNode() = %v, want %v", got, tt.want)
}
})
}
}