MCPcopy
hub / github.com/kubernetes/client-go / validateEvent

Function validateEvent

tools/record/events_cache_test.go:95–128  ·  view source on GitHub ↗
(messagePrefix string, actualEvent *v1.Event, expectedEvent *v1.Event, t *testing.T)

Source from the content-addressed store, hash-verified

93}
94
95func validateEvent(messagePrefix string, actualEvent *v1.Event, expectedEvent *v1.Event, t *testing.T) (*v1.Event, error) {
96 recvEvent := *actualEvent
97 expectCompression := expectedEvent.Count > 1
98 t.Logf("%v - expectedEvent.Count is %d\n", messagePrefix, expectedEvent.Count)
99 // Just check that the timestamp was set.
100 if recvEvent.FirstTimestamp.IsZero() || recvEvent.LastTimestamp.IsZero() {
101 t.Errorf("%v - timestamp wasn't set: %#v", messagePrefix, recvEvent)
102 }
103 actualFirstTimestamp := recvEvent.FirstTimestamp
104 actualLastTimestamp := recvEvent.LastTimestamp
105 if actualFirstTimestamp.Equal(&actualLastTimestamp) {
106 if expectCompression {
107 t.Errorf("%v - FirstTimestamp (%q) and LastTimestamp (%q) must be different to indicate event compression happened, but were the same. Actual Event: %#v", messagePrefix, actualFirstTimestamp, actualLastTimestamp, recvEvent)
108 }
109 } else {
110 if expectedEvent.Count == 1 {
111 t.Errorf("%v - FirstTimestamp (%q) and LastTimestamp (%q) must be equal to indicate only one occurrence of the event, but were different. Actual Event: %#v", messagePrefix, actualFirstTimestamp, actualLastTimestamp, recvEvent)
112 }
113 }
114 // Temp clear time stamps for comparison because actual values don't matter for comparison
115 recvEvent.FirstTimestamp = expectedEvent.FirstTimestamp
116 recvEvent.LastTimestamp = expectedEvent.LastTimestamp
117 // Check that name has the right prefix.
118 if n, en := recvEvent.Name, expectedEvent.Name; !strings.HasPrefix(n, en) {
119 t.Errorf("%v - Name '%v' does not contain prefix '%v'", messagePrefix, n, en)
120 }
121 recvEvent.Name = expectedEvent.Name
122 if e, a := expectedEvent, &recvEvent; !reflect.DeepEqual(e, a) {
123 t.Errorf("%v - diff: %s", messagePrefix, diff.ObjectGoPrintDiff(e, a))
124 }
125 recvEvent.FirstTimestamp = actualFirstTimestamp
126 recvEvent.LastTimestamp = actualLastTimestamp
127 return actualEvent, nil
128}
129
130// TestEventAggregatorByReasonFunc ensures that two events are aggregated if they vary only by event.message
131func TestEventAggregatorByReasonFunc(t *testing.T) {

Callers 4

TestEventCorrelatorFunction · 0.85
TestEventfFunction · 0.85
TestEventfNoNamespaceFunction · 0.85
TestMultiSinkCacheFunction · 0.85

Calls 2

LogfMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected