-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetrics_test.go
More file actions
79 lines (66 loc) · 2.02 KB
/
metrics_test.go
File metadata and controls
79 lines (66 loc) · 2.02 KB
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
package metrics
import (
"os"
"reflect"
"testing"
)
func must(t *testing.T, err error) {
if err != nil {
t.Fatal(err)
}
}
func assertDeepEqual(t *testing.T, name string, got, want interface{}) {
if !reflect.DeepEqual(got, want) {
t.Errorf("[%s], got:\n\t%#v\nwant:\n\t%#v\n", name, got, want)
}
}
func TestMetricTags(t *testing.T) {
r := newFakeMetricsReporter()
Reporter = r
defer resetReporter()
must(t, Count("testcount", 42, nil, 1.0))
assertDeepEqual(t, "no app name and no tags", r.LastCountMetric, &intMetric{
metric{"testcount", map[string]string{}, 1.0},
42,
})
must(t, Count("testcount", 42, map[string]string{"foo": "bar"}, 1.0))
assertDeepEqual(t, "no app name and some tags", r.LastCountMetric, &intMetric{
metric{"testcount", map[string]string{"foo": "bar"}, 1.0},
42,
})
os.Setenv("EMPIRE_APPNAME", "testapp")
os.Setenv("EMPIRE_PROCESS", "testprocess")
os.Setenv("EMPIRE_RELEASE", "v1")
SetEmpireDefaultTags()
defer resetDefaultTags()
must(t, Count("testcount", 42, nil, 1.0))
assertDeepEqual(t, "app name and no tags", r.LastCountMetric, &intMetric{
metric{"testcount",
map[string]string{"empire.app.name": "testapp", "empire.app.process": "testprocess",
"empire.app.release": "v1"},
1.0},
42,
})
must(t, Count("testcount", 42, map[string]string{"foo": "bar"}, 1.0))
assertDeepEqual(t, "app name and some tags", r.LastCountMetric, &intMetric{
metric{"testcount",
map[string]string{"foo": "bar", "empire.app.name": "testapp", "empire.app.process": "testprocess",
"empire.app.release": "v1"},
1.0},
42,
})
}
func TestTime(t *testing.T) {
r := newFakeMetricsReporter()
Reporter = r
defer resetReporter()
tm := Time("mytiming", map[string]string{"yolo": "bolo"}, 1.0)
tm.SetTags(map[string]string{"foo": "bar"})
tm.Done()
last := r.LastTimeInMillisecondsMetric
gotTags := last.Tags
wantTags := map[string]string{"yolo": "bolo", "foo": "bar"}
if !reflect.DeepEqual(gotTags, wantTags) {
t.Errorf("got tags:\n\t%#v\nwanted these:\n\t%#v", gotTags, wantTags)
}
}