mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-05-23 17:43:25 +00:00
46 lines
1.5 KiB
Go
46 lines
1.5 KiB
Go
package testing
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/openshift/library-go/pkg/operator/events"
|
|
"github.com/openshift/library-go/pkg/operator/events/eventstesting"
|
|
clienttesting "k8s.io/client-go/testing"
|
|
"k8s.io/client-go/util/workqueue"
|
|
)
|
|
|
|
type FakeSyncContext struct {
|
|
queueKey string
|
|
queue workqueue.RateLimitingInterface
|
|
recorder events.Recorder
|
|
}
|
|
|
|
func (f FakeSyncContext) Queue() workqueue.RateLimitingInterface { return f.queue }
|
|
func (f FakeSyncContext) QueueKey() string { return f.queueKey }
|
|
func (f FakeSyncContext) Recorder() events.Recorder { return f.recorder }
|
|
|
|
func NewFakeSyncContext(t *testing.T, queueKey string) *FakeSyncContext {
|
|
return &FakeSyncContext{
|
|
queueKey: queueKey,
|
|
queue: workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()),
|
|
recorder: eventstesting.NewTestingEventRecorder(t),
|
|
}
|
|
}
|
|
|
|
// AssertActions asserts the actual actions have the expected action verb
|
|
func AssertActions(t *testing.T, actualActions []clienttesting.Action, expectedVerbs ...string) {
|
|
if len(actualActions) != len(expectedVerbs) {
|
|
t.Fatalf("expected %d call but got: %#v", len(expectedVerbs), actualActions)
|
|
}
|
|
for i, expected := range expectedVerbs {
|
|
if actualActions[i].GetVerb() != expected {
|
|
t.Errorf("expected %s action but got: %#v", expected, actualActions[i])
|
|
}
|
|
}
|
|
}
|
|
|
|
// AssertNoActions asserts no actions are happened
|
|
func AssertNoActions(t *testing.T, actualActions []clienttesting.Action) {
|
|
AssertActions(t, actualActions)
|
|
}
|