-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeacon_test.go
67 lines (55 loc) · 1.77 KB
/
beacon_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
package beacon
import (
"bytes"
"github.com/stretchr/testify/assert"
"testing"
)
func eventToString(t *testing.T, ev Event) string {
var buf bytes.Buffer
inner, ok := ev.(*event)
assert.True(t, ok)
err := inner.writeKubernetesBeaconLine(&buf)
assert.Nil(t, err)
return buf.String()
}
func TestWriteKubernetesBeaconLine(t *testing.T) {
ev := NewEvent(
"THE-LABEL",
Error,
Count,
7.0,
)
line := eventToString(t, ev)
assert.Contains(t, line, "section.io-beacon:{", "prefix")
assert.Contains(t, line, `"label":"THE-LABEL",`, "label")
assert.Contains(t, line, `"severity":"error",`, "severity")
assert.Contains(t, line, `"metric":{"type":"count","value":7}`, "metric")
assert.Contains(t, line, "}\n", "suffix")
ev = NewEvent(
"other-label",
Info,
Timing,
3.14,
).
AddContext("account", "Peterson").
AddAnnotation("timing_unit", "ms").
SetCorrelationID("abc123")
line = eventToString(t, ev)
assert.Contains(t, line, `"label":"other-label",`, "label")
assert.Contains(t, line, `"severity":"info",`, "severity")
assert.Contains(t, line, `"metric":{"type":"timing","value":3.14}`, "metric")
assert.Contains(t, line, `"context":{"account":"Peterson"}`, "context")
assert.Contains(t, line, `"annotations":{"timing_unit":"ms"}`, "annotations")
assert.Contains(t, line, `"correlationId":"abc123"`, "correlation id")
}
func TestBeaconSingleError(t *testing.T) {
ev := BeaconSingleInfoCount("test", map[string]string{
"error": "one",
"other": "two",
})
line := eventToString(t, ev)
assert.Contains(t, line, `"label":"test",`, "label")
assert.Contains(t, line, `"severity":"info",`, "severity")
assert.Contains(t, line, `"metric":{"type":"count","value":1}`, "metric")
assert.Contains(t, line, `"annotations":{"error":"one","other":"two"}`, "annotations")
}