-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreporter_test.go
95 lines (81 loc) · 2.11 KB
/
reporter_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
package statsd
import (
"testing"
"time"
)
func init() {
}
var testTags = MetricTags{
"layer": "service",
"service": "users",
}
var testErrTags = MetricTags{
"layer": "service",
"service": "users",
"error": "an-error",
}
func TestReportFuncCall(t *testing.T) {
client = newMockStatter(false)
config = checkConfig(&MetricsConfig{
EnvName: "testing",
StuckFunctionTimeout: time.Second,
})
var testReporter = NewReporter()
testReporter.ReportCall(testTags)
}
func TestReportFuncCallWithoutTiming(t *testing.T) {
client = newMockStatter(false)
config = checkConfig(&MetricsConfig{
EnvName: "testing",
StuckFunctionTimeout: time.Second,
})
var testReporter = NewReporterFromConfig(&ReporterConfig{
ReportTiming: false,
FuncName: "some-test",
})
testReporter.ReportCall(testTags)
}
func TestReportFuncError(t *testing.T) {
var testReporter = NewReporter()
testReporter.ReportError(testErrTags)
}
func TestReportFuncTiming(t *testing.T) {
var testReporter = NewReporter()
stopFn := testReporter.ReportCall(testTags)
time.Sleep(500 * time.Millisecond)
stopFn()
}
func TestReportFuncTimingStuck(t *testing.T) {
var testReporter = NewReporter()
stopFn := testReporter.ReportCall(testTags)
time.Sleep(2 * time.Second)
stopFn()
}
func TestNewReporterFromConfig(t *testing.T) {
var reporter = NewReporterFromConfig(&ReporterConfig{
ReportTiming: true,
FuncName: "something-arbitrary",
})
reporter.ReportError(testTags)
}
func TestNewReporterWithEmptyTags(t *testing.T) {
var reporter = NewReporterFromConfig(&ReporterConfig{
ReportTiming: true,
FuncName: "something-arbitrary",
})
reporter.ReportCall()
}
func TestNewReporterWithExtraTags(t *testing.T) {
var reporter = NewReporterFromConfig(&ReporterConfig{
ReportTiming: true,
FuncName: "something-arbitrary",
})
reporter.ReportCall(testTags.With("extra", "thing"))
}
func TestNewReporterWithEmptyExtraTags(t *testing.T) {
var reporter = NewReporterFromConfig(&ReporterConfig{
ReportTiming: true,
FuncName: "something-arbitrary",
})
reporter.ReportCall(MetricTags{}.With("extra", "thing"))
}