forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 7
/
event_test.go
43 lines (34 loc) · 1.22 KB
/
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
package qlog
import (
"bytes"
"encoding/json"
"time"
"github.com/francoispqt/gojay"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
type mevent struct{}
var _ eventDetails = mevent{}
func (mevent) Category() category { return categoryConnectivity }
func (mevent) Name() string { return "mevent" }
func (mevent) IsNil() bool { return false }
func (mevent) MarshalJSONObject(enc *gojay.Encoder) { enc.StringKey("event", "details") }
var _ = Describe("Events", func() {
It("marshals the fields before the event details", func() {
buf := &bytes.Buffer{}
enc := gojay.NewEncoder(buf)
Expect(enc.Encode(event{
RelativeTime: 1337 * time.Microsecond,
eventDetails: mevent{},
})).To(Succeed())
var decoded interface{}
Expect(json.Unmarshal(buf.Bytes(), &decoded)).To(Succeed())
Expect(decoded).To(HaveLen(3))
Expect(decoded).To(HaveKeyWithValue("time", 1.337))
Expect(decoded).To(HaveKeyWithValue("name", "connectivity:mevent"))
Expect(decoded).To(HaveKey("data"))
data := decoded.(map[string]interface{})["data"].(map[string]interface{})
Expect(data).To(HaveLen(1))
Expect(data).To(HaveKeyWithValue("event", "details"))
})
})