-
Notifications
You must be signed in to change notification settings - Fork 14
/
main_test.go
125 lines (95 loc) · 2.08 KB
/
main_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"testing"
"time"
)
func Test_sequental(t *testing.T) {
assets := []struct {
IPAddr string
Index int
}{
{"10.0.0.1", 0},
{"10.0.0.2", 1},
{"10.0.0.3", 2},
{"10.0.0.1", 3},
{"10.0.0.2", 4},
{"10.0.0.3", 5},
{"10.0.0.1", 6},
}
list := []string{"10.0.0.1", "10.0.0.2", "10.0.0.3"}
for i := 0; i < len(assets); i++ {
a := assets[i]
ip := sequental(i, list)
if ip != a.IPAddr {
t.Error("invalid ip:", a.IPAddr)
}
}
}
func Test_getMetric(t *testing.T) {
s := []map[string]time.Duration{}
s = append(s, map[string]time.Duration{
"DATA": time.Second * 1,
})
s = append(s, map[string]time.Duration{
"DATA": time.Second * 2,
})
max, min, med := getMetric("DATA", s)
if max != time.Second*1 {
t.Error("max duration invalid")
}
if min != time.Second*2 {
t.Error("min duration invalid")
}
if d, _ := time.ParseDuration("1.5s"); med != d {
t.Error("med duration invalid")
}
}
func Test_countMetric(t *testing.T) {
s := []map[string]time.Duration{}
s = append(s, map[string]time.Duration{
"DATA": time.Second * 1,
})
s = append(s, map[string]time.Duration{
"DATA": time.Second * 2,
})
s = append(s, map[string]time.Duration{
"QUIT": time.Second * 2,
})
cnt := countMetric("DATA", s)
if cnt != 2 {
t.Error("Invalid key count:", cnt)
}
cnt = countMetric("QUIT", s)
if cnt != 1 {
t.Error("Invalid key count:", cnt)
}
}
func Test_metricKeys(t *testing.T) {
s := []map[string]time.Duration{}
s = append(s, map[string]time.Duration{
"DATA": time.Second * 1,
})
s = append(s, map[string]time.Duration{
"MAIL": time.Second * 1,
})
s = append(s, map[string]time.Duration{
"QUIT": time.Second * 1,
})
keys := metricKeys(s)
if len(keys) != 3 {
t.Error("invalid length")
}
}
func Test_isContain(t *testing.T) {
list := []string{"10.0.0.1", "10.0.0.2", "10.0.0.3"}
if !isContain("10.0.0.1", list) {
t.Error("Key not found")
}
if isContain("10.0.0.4", list) {
t.Error("Key found! oha.")
}
}
//func Test_createBodyFixedSize(t *testing.T) {
// body := createBodyFixedSize(10)
// fmt.Println(body)
// }