/
event_test.go
57 lines (51 loc) · 944 Bytes
/
event_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
package main
import (
"testing"
rpb "github.com/blind-oracle/riemann-relay/riemannpb"
"github.com/stretchr/testify/assert"
)
const (
jsTest = `
{
"host": "blah",
"service": "foo",
"description": "baz",
"state": "ok",
"tags": ["tag1", "tag2"],
"metric": 123,
"time": "2018-04-10T13:36:04.787Z",
"attributes": [
{
"key": "key1",
"value": "val1"
}
]
}
`
)
func Test_eventFromJSON(t *testing.T) {
ev := &rpb.Event{
Host: "blah",
Service: "foo",
Description: "baz",
State: "ok",
Tags: []string{"tag1", "tag2"},
Attributes: []*rpb.Attribute{
{
Key: "key1",
Value: "val1",
},
},
Ttl: 0,
TimeMicros: 1523367364787000,
MetricD: 123,
}
ev2, err := eventFromJSON([]byte(jsTest))
assert.Nil(t, err)
assert.Equal(t, ev, ev2)
}
func Benchmark_eventFromJSON(b *testing.B) {
for i := 0; i < b.N; i++ {
eventFromJSON([]byte(jsTest))
}
}