mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
39da5bd927
* fix: re-use the maxQueuedEvents Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> * fix: use the apierrors.IsNotFound instead of checking a specfic error msg Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> --------- Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> Co-authored-by: shuting <shuting@nirmata.com>
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package event
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/go-logr/logr"
|
|
corev1 "k8s.io/api/core/v1"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
|
"k8s.io/client-go/kubernetes/fake"
|
|
clienttesting "k8s.io/client-go/testing"
|
|
)
|
|
|
|
func TestEventGenerator(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
eventCreated := make(chan struct{})
|
|
clientset := fake.NewSimpleClientset()
|
|
clientset.PrependReactor("create", "events", func(action clienttesting.Action) (handled bool, ret runtime.Object, err error) {
|
|
eventCreated <- struct{}{}
|
|
return true, nil, nil
|
|
})
|
|
|
|
logger := logr.Discard()
|
|
|
|
eventsClient := clientset.EventsV1()
|
|
eventGenerator := NewEventGenerator(eventsClient, logger, 1000)
|
|
|
|
go eventGenerator.Run(ctx, Workers)
|
|
time.Sleep(1 * time.Second)
|
|
|
|
info := Info{
|
|
Regarding: corev1.ObjectReference{
|
|
Kind: "Pod",
|
|
Name: "pod",
|
|
Namespace: "default",
|
|
},
|
|
Reason: "TestReason",
|
|
Action: "TestAction",
|
|
Message: "TestMessage",
|
|
Source: PolicyController,
|
|
}
|
|
|
|
eventGenerator.Add(info)
|
|
|
|
select {
|
|
case <-eventCreated:
|
|
case <-time.After(wait.ForeverTestTimeout):
|
|
t.Fatal("event not created")
|
|
}
|
|
}
|