forked from codesenberg/bombardier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_map_test.go
80 lines (73 loc) · 1.28 KB
/
error_map_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
package main
import (
"errors"
"reflect"
"testing"
)
func TestErrorMapAdd(t *testing.T) {
m := newErrorMap()
err := errors.New("add")
m.add(err)
if c := m.get(err); c != 1 {
t.Error(c)
}
}
func TestErrorMapGet(t *testing.T) {
m := newErrorMap()
err := errors.New("get")
if c := m.get(err); c != 0 {
t.Error(c)
}
}
func TestByFrequency(t *testing.T) {
m := newErrorMap()
a := errors.New("A")
b := errors.New("B")
c := errors.New("C")
m.add(a)
m.add(a)
m.add(b)
m.add(b)
m.add(b)
m.add(c)
e := errorsByFrequency{
{"B", 3},
{"A", 2},
{"C", 1},
}
if a := m.byFrequency(); !reflect.DeepEqual(a, e) {
t.Logf("Expected: %+v", e)
t.Logf("Got: %+v", a)
t.Fail()
}
}
func TestErrorWithCountToStringConversion(t *testing.T) {
ewc := errorWithCount{"A", 1}
exp := "<A:1>"
if act := ewc.String(); act != exp {
t.Logf("Expected: %+v", exp)
t.Logf("Got: %+v", act)
t.Fail()
}
}
func BenchmarkErrorMapAdd(b *testing.B) {
m := newErrorMap()
err := errors.New("benchmark")
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
m.add(err)
}
})
}
func BenchmarkErrorMapGet(b *testing.B) {
m := newErrorMap()
err := errors.New("benchmark")
m.add(err)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
m.get(err)
}
})
}