-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmocknode_test.go
66 lines (64 loc) · 1.51 KB
/
mocknode_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
package balancer
import (
"testing"
"time"
)
func TestMockNode_AverageResponseTime(t *testing.T) {
type fields struct {
Node Node
Weight int
load int64
RequestCount uint64
TotalRequestTime uint64
Host string
Healthy bool
}
tests := []struct {
name string
fields fields
want time.Duration
}{
{
name: "basic time calc",
fields: fields{
Node: nil,
Weight: 1,
load: 0,
RequestCount: 100,
TotalRequestTime: 100 * 100,
Healthy: true,
Host: "127.0.0.1",
},
want: time.Duration(100 * time.Nanosecond),
},
{
name: "basic time calc again :)",
fields: fields{
Node: nil,
Weight: 1,
load: 0,
RequestCount: 100,
TotalRequestTime: uint64(100 * time.Second),
Healthy: true,
Host: "127.0.0.1",
},
want: time.Duration(time.Second),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
u := &MockNode{
Node: tt.fields.Node,
Weight: tt.fields.Weight,
load: tt.fields.load,
requestCount: tt.fields.RequestCount,
totalRequestTime: tt.fields.TotalRequestTime,
nodeID: tt.fields.Host,
healthy: tt.fields.Healthy,
}
if got := u.AverageResponseTime(); got != tt.want {
t.Errorf("MockNode.AverageResponseTime() = %v, want %v", got, tt.want)
}
})
}
}