forked from openshift/library-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recorder_testing.go
46 lines (35 loc) · 1.25 KB
/
recorder_testing.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
package eventstesting
import (
"fmt"
"testing"
"github.com/openshift/library-go/pkg/operator/events"
)
type TestingEventRecorder struct {
t *testing.T
component string
}
// NewTestingEventRecorder provides event recorder that will log all recorded events to the error log.
func NewTestingEventRecorder(t *testing.T) events.Recorder {
return &TestingEventRecorder{t: t, component: "test"}
}
func (r *TestingEventRecorder) ComponentName() string {
return r.component
}
func (r *TestingEventRecorder) ForComponent(c string) events.Recorder {
return &TestingEventRecorder{t: r.t, component: c}
}
func (r *TestingEventRecorder) WithComponentSuffix(suffix string) events.Recorder {
return r.ForComponent(fmt.Sprintf("%s-%s", r.ComponentName(), suffix))
}
func (r *TestingEventRecorder) Event(reason, message string) {
r.t.Logf("Event: %v: %v", reason, message)
}
func (r *TestingEventRecorder) Eventf(reason, messageFmt string, args ...interface{}) {
r.Event(reason, fmt.Sprintf(messageFmt, args...))
}
func (r *TestingEventRecorder) Warning(reason, message string) {
r.t.Logf("Warning: %v: %v", reason, message)
}
func (r *TestingEventRecorder) Warningf(reason, messageFmt string, args ...interface{}) {
r.Warning(reason, fmt.Sprintf(messageFmt, args...))
}