Debian Codegraph @

event/eventtest/capture.go

raw symbols SCIP
1 package eventtest
2
3 import (
4 "context"
5
6 "golang.org/x/exp/event"
7 )
8
9 type CaptureHandler struct {
10 Got []event.Event
11 }
12
13 func (h *CaptureHandler) Event(ctx context.Context, ev *event.Event) context.Context {
14 h.Got = append(h.Got, *ev)
15 got := &h.Got[len(h.Got)-1]
16 got.Labels = make([]event.Label, len(ev.Labels))
17 copy(got.Labels, ev.Labels)
18 return ctx
19 }
20
21 func (h *CaptureHandler) Reset() {
22 if len(h.Got) > 0 {
23 h.Got = h.Got[:0]
24 }
25 }
26
27 func NewCapture() (context.Context, *CaptureHandler) {
28 h := &CaptureHandler{}
29 ctx := event.WithExporter(context.Background(), event.NewExporter(h, ExporterOptions()))
30 return ctx, h
31 }