-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvanguard_test.go
56 lines (50 loc) · 1.19 KB
/
vanguard_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
package vanguard_test
import (
"testing"
"github.com/srikrsna/vanguard"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"
)
func TestAssertions(t *testing.T) {
l := zaptest.NewLogger(t, zaptest.Level(zapcore.ErrorLevel))
defer l.Sync()
for _, tc := range Cases {
tc := tc
t.Run(tc.Name(), func(t *testing.T) {
t.Parallel()
assert, err := vanguard.NewVanguard(
vanguard.WithLevelMatcher(tc.LevelMatcher),
vanguard.WithResourceMatcher(tc.ResourceMatcher),
)
if err != nil {
l.Fatal("unable to compile assertions", zap.Error(err))
}
tc.Evaluate(assert, l)
})
}
}
func BenchmarkAssertions(b *testing.B) {
l := zaptest.NewLogger(b, zaptest.Level(zapcore.ErrorLevel))
defer l.Sync()
b.ResetTimer()
for _, bc := range Cases {
bc := bc
b.Run(bc.Name(), func(b *testing.B) {
assert, err := vanguard.NewVanguard(
vanguard.WithLevelMatcher(bc.LevelMatcher),
vanguard.WithResourceMatcher(bc.ResourceMatcher),
)
if err != nil {
l.Fatal("unable to compile assertions", zap.Error(err))
}
b.ResetTimer()
b.ReportAllocs()
b.RunParallel(func(p *testing.PB) {
for p.Next() {
bc.Evaluate(assert, l)
}
})
})
}
}