You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reason: "Events should always be emitted when there is no filter function.",
166
+
inputEvent: basicInputEvent,
167
+
want: basicInputEvent,
168
+
},
169
+
"AllowAllFilter": {
170
+
reason: "Events should always be emitted when the filter function allows all events.",
171
+
filterFunctions: []FilterFn{
172
+
func(_ runtime.Object, _Event) bool {
173
+
returnfalse
174
+
},
175
+
},
176
+
inputEvent: basicInputEvent,
177
+
want: basicInputEvent,
178
+
},
179
+
"DenyAllFilter": {
180
+
reason: "Events should never be emitted when the filter function denies all events.",
181
+
filterFunctions: []FilterFn{
182
+
func(_ runtime.Object, _Event) bool {
183
+
returntrue
184
+
},
185
+
},
186
+
inputEvent: basicInputEvent,
187
+
want: emptyEvent,
188
+
},
189
+
"NamespaceFilterDeny": {
190
+
reason: "Events should be denied when the filter function denies events from a specific namespace.",
191
+
filterFunctions: []FilterFn{
192
+
func(o runtime.Object, _Event) bool {
193
+
meta, err:=meta.Accessor(o)
194
+
iferr!=nil {
195
+
returnfalse
196
+
}
197
+
returnmeta.GetNamespace() ==forbiddenNamespace
198
+
},
199
+
},
200
+
inputResource: &inputCMInForbiddenNamespace,
201
+
inputEvent: basicInputEvent,
202
+
want: emptyEvent,
203
+
},
204
+
"NamespaceFilterAllow": {
205
+
reason: "Events should be emitted when the filter function allows events from all namespaces but a specific one, and the resource is not in that namespace.",
206
+
filterFunctions: []FilterFn{
207
+
func(o runtime.Object, _Event) bool {
208
+
meta, err:=meta.Accessor(o)
209
+
iferr!=nil {
210
+
returnfalse
211
+
}
212
+
returnmeta.GetNamespace() ==forbiddenNamespace
213
+
},
214
+
},
215
+
inputResource: &inputCMInAllowedNamespace,
216
+
inputEvent: basicInputEvent,
217
+
want: basicInputEvent,
218
+
},
219
+
"WithAnnotations": {
220
+
reason: "Events should be emitted with annotations when WithAnnotations is used.",
221
+
annotations: []string{
222
+
"testKey", "testValue",
223
+
},
224
+
inputEvent: basicInputEvent,
225
+
want: Event{
226
+
Type: TypeNormal,
227
+
Reason: basicInputEvent.Reason,
228
+
Message: basicInputEvent.Message,
229
+
Annotations: map[string]string{
230
+
"testKey": "testValue",
231
+
},
232
+
},
233
+
},
234
+
}
235
+
236
+
forname, tc:=rangecases {
237
+
t.Run(name, func(t*testing.T) {
238
+
// Test with NewAPIRecorder
239
+
// AND WithAnnotations to check if it correctly preserves the filter functions, and also to test annotations
0 commit comments