-
Notifications
You must be signed in to change notification settings - Fork 107
/
event_mock.go
102 lines (96 loc) · 2.95 KB
/
event_mock.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package fake
import (
apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1/common"
"sigs.k8s.io/controller-runtime/pkg/client"
"sync"
)
// MockEvent is a mock implementation of eventsender.IEvent.
//
// func TestSomethingThatUsesIEvent(t *testing.T) {
//
// // make and configure a mocked eventsender.IEvent
// mockedIEvent := &MockEvent{
// EmitFunc: func(phase apicommon.KeptnPhaseType, eventType string, reconcileObject client.Object, status string, message string, version string) {
// panic("mock out the Emit method")
// },
// }
//
// // use mockedIEvent in code that requires eventsender.IEvent
// // and then make assertions.
//
// }
type MockEvent struct {
// EmitFunc mocks the Emit method.
EmitFunc func(phase apicommon.KeptnPhaseType, eventType string, reconcileObject client.Object, status string, message string, version string)
// calls tracks calls to the methods.
calls struct {
// Emit holds details about calls to the Emit method.
Emit []struct {
// Phase is the phase argument value.
Phase apicommon.KeptnPhaseType
// EventType is the eventType argument value.
EventType string
// ReconcileObject is the reconcileObject argument value.
ReconcileObject client.Object
// Status is the status argument value.
Status string
// Message is the message argument value.
Message string
// Version is the version argument value.
Version string
}
}
lockEmit sync.RWMutex
}
// Emit calls EmitFunc.
func (mock *MockEvent) Emit(phase apicommon.KeptnPhaseType, eventType string, reconcileObject client.Object, status string, message string, version string) {
if mock.EmitFunc == nil {
panic("MockEvent.EmitFunc: method is nil but IEvent.Emit was just called")
}
callInfo := struct {
Phase apicommon.KeptnPhaseType
EventType string
ReconcileObject client.Object
Status string
Message string
Version string
}{
Phase: phase,
EventType: eventType,
ReconcileObject: reconcileObject,
Status: status,
Message: message,
Version: version,
}
mock.lockEmit.Lock()
mock.calls.Emit = append(mock.calls.Emit, callInfo)
mock.lockEmit.Unlock()
mock.EmitFunc(phase, eventType, reconcileObject, status, message, version)
}
// EmitCalls gets all the calls that were made to Emit.
// Check the length with:
//
// len(mockedIEvent.EmitCalls())
func (mock *MockEvent) EmitCalls() []struct {
Phase apicommon.KeptnPhaseType
EventType string
ReconcileObject client.Object
Status string
Message string
Version string
} {
var calls []struct {
Phase apicommon.KeptnPhaseType
EventType string
ReconcileObject client.Object
Status string
Message string
Version string
}
mock.lockEmit.RLock()
calls = mock.calls.Emit
mock.lockEmit.RUnlock()
return calls
}