repair the test for rb status controller
Signed-off-by: chaosi-zju <chaosi@zju.edu.cn>
This commit is contained in:
parent
37dfa37515
commit
16a4f42862
|
@ -34,6 +34,7 @@ import (
|
|||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||
|
||||
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
|
||||
"github.com/karmada-io/karmada/pkg/resourceinterpreter/default/native"
|
||||
"github.com/karmada-io/karmada/pkg/util/fedinformer/genericmanager"
|
||||
"github.com/karmada-io/karmada/pkg/util/gclient"
|
||||
)
|
||||
|
@ -100,6 +101,9 @@ func TestCRBStatusController_Reconcile(t *testing.T) {
|
|||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "binding",
|
||||
Namespace: "default",
|
||||
// finalizers field is required when deletionTimestamp is defined, otherwise will encounter the
|
||||
// error: `refusing to create obj binding with metadata.deletionTimestamp but no finalizers`.
|
||||
Finalizers: []string{"test"},
|
||||
DeletionTimestamp: &preTime,
|
||||
},
|
||||
Spec: workv1alpha2.ResourceBindingSpec{
|
||||
|
@ -119,6 +123,7 @@ func TestCRBStatusController_Reconcile(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := generateCRBStatusController()
|
||||
c.ResourceInterpreter = FakeResourceInterpreter{DefaultInterpreter: native.NewDefaultInterpreter()}
|
||||
|
||||
// Prepare req
|
||||
req := controllerruntime.Request{
|
||||
|
@ -130,9 +135,7 @@ func TestCRBStatusController_Reconcile(t *testing.T) {
|
|||
|
||||
// Prepare binding and create it in client
|
||||
if tt.binding != nil {
|
||||
if err := c.Client.Create(context.Background(), tt.binding); err != nil {
|
||||
t.Fatalf("Failed to create binding: %v", err)
|
||||
}
|
||||
c.Client = fake.NewClientBuilder().WithScheme(gclient.NewSchema()).WithObjects(tt.binding).WithStatusSubresource(tt.binding).Build()
|
||||
}
|
||||
|
||||
res, err := c.Reconcile(context.Background(), req)
|
||||
|
@ -192,6 +195,7 @@ func TestCRBStatusController_syncBindingStatus(t *testing.T) {
|
|||
c := generateCRBStatusController()
|
||||
c.DynamicClient = dynamicfake.NewSimpleDynamicClient(scheme.Scheme,
|
||||
&corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: tt.podNameInDynamicClient, Namespace: "default"}})
|
||||
c.ResourceInterpreter = FakeResourceInterpreter{DefaultInterpreter: native.NewDefaultInterpreter()}
|
||||
|
||||
binding := &workv1alpha2.ClusterResourceBinding{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
@ -204,9 +208,7 @@ func TestCRBStatusController_syncBindingStatus(t *testing.T) {
|
|||
}
|
||||
|
||||
if tt.resourceExistInClient {
|
||||
if err := c.Client.Create(context.Background(), binding); err != nil {
|
||||
t.Fatalf("Failed to create binding: %v", err)
|
||||
}
|
||||
c.Client = fake.NewClientBuilder().WithScheme(gclient.NewSchema()).WithObjects(binding).WithStatusSubresource(binding).Build()
|
||||
}
|
||||
|
||||
err := c.syncBindingStatus(context.Background(), binding)
|
||||
|
|
|
@ -34,6 +34,8 @@ import (
|
|||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||
|
||||
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
|
||||
"github.com/karmada-io/karmada/pkg/resourceinterpreter"
|
||||
"github.com/karmada-io/karmada/pkg/resourceinterpreter/default/native"
|
||||
"github.com/karmada-io/karmada/pkg/util/fedinformer/genericmanager"
|
||||
"github.com/karmada-io/karmada/pkg/util/gclient"
|
||||
)
|
||||
|
@ -100,6 +102,9 @@ func TestRBStatusController_Reconcile(t *testing.T) {
|
|||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "binding",
|
||||
Namespace: "default",
|
||||
// finalizers field is required when deletionTimestamp is defined, otherwise will encounter the
|
||||
// error: `refusing to create obj binding with metadata.deletionTimestamp but no finalizers`.
|
||||
Finalizers: []string{"test"},
|
||||
DeletionTimestamp: &preTime,
|
||||
},
|
||||
Spec: workv1alpha2.ResourceBindingSpec{
|
||||
|
@ -119,6 +124,7 @@ func TestRBStatusController_Reconcile(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := generateRBStatusController()
|
||||
c.ResourceInterpreter = FakeResourceInterpreter{DefaultInterpreter: native.NewDefaultInterpreter()}
|
||||
|
||||
// Prepare req
|
||||
req := controllerruntime.Request{
|
||||
|
@ -130,9 +136,7 @@ func TestRBStatusController_Reconcile(t *testing.T) {
|
|||
|
||||
// Prepare binding and create it in client
|
||||
if tt.binding != nil {
|
||||
if err := c.Client.Create(context.Background(), tt.binding); err != nil {
|
||||
t.Fatalf("Failed to create binding: %v", err)
|
||||
}
|
||||
c.Client = fake.NewClientBuilder().WithScheme(gclient.NewSchema()).WithObjects(tt.binding).WithStatusSubresource(tt.binding).Build()
|
||||
}
|
||||
|
||||
res, err := c.Reconcile(context.Background(), req)
|
||||
|
@ -192,6 +196,7 @@ func TestRBStatusController_syncBindingStatus(t *testing.T) {
|
|||
c := generateRBStatusController()
|
||||
c.DynamicClient = dynamicfake.NewSimpleDynamicClient(scheme.Scheme,
|
||||
&corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: tt.podNameInDynamicClient, Namespace: "default"}})
|
||||
c.ResourceInterpreter = FakeResourceInterpreter{DefaultInterpreter: native.NewDefaultInterpreter()}
|
||||
|
||||
binding := &workv1alpha2.ResourceBinding{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
@ -204,9 +209,7 @@ func TestRBStatusController_syncBindingStatus(t *testing.T) {
|
|||
}
|
||||
|
||||
if tt.resourceExistInClient {
|
||||
if err := c.Client.Create(context.Background(), binding); err != nil {
|
||||
t.Fatalf("Failed to create binding: %v", err)
|
||||
}
|
||||
c.Client = fake.NewClientBuilder().WithScheme(gclient.NewSchema()).WithObjects(binding).WithStatusSubresource(binding).Build()
|
||||
}
|
||||
|
||||
err := c.syncBindingStatus(context.Background(), binding)
|
||||
|
@ -219,3 +222,13 @@ func TestRBStatusController_syncBindingStatus(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
var _ resourceinterpreter.ResourceInterpreter = &FakeResourceInterpreter{}
|
||||
|
||||
type FakeResourceInterpreter struct {
|
||||
*native.DefaultInterpreter
|
||||
}
|
||||
|
||||
func (f FakeResourceInterpreter) Start(_ context.Context) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue