@@ -7,14 +7,20 @@ import (
77 gameKruiseV1alpha1 "github.com/openkruise/kruise-game/apis/v1alpha1"
88 corev1 "k8s.io/api/core/v1"
99 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+ "k8s.io/apimachinery/pkg/runtime"
1011 "k8s.io/apimachinery/pkg/types"
12+ "sigs.k8s.io/controller-runtime/pkg/client"
1113 "sigs.k8s.io/controller-runtime/pkg/client/fake"
1214)
1315
1416// TestTopologyRater_Basic covers the main happy-path calculation using defaults.
1517func TestTopologyRater_Basic (t * testing.T ) {
1618 ctx := context .TODO ()
1719
20+ scheme := runtime .NewScheme ()
21+ _ = corev1 .AddToScheme (scheme )
22+ _ = gameKruiseV1alpha1 .AddToScheme (scheme )
23+
1824 pod := & corev1.Pod {
1925 ObjectMeta : metav1.ObjectMeta {
2026 Namespace : "default" ,
@@ -28,7 +34,14 @@ func TestTopologyRater_Basic(t *testing.T) {
2834 },
2935 }
3036
31- cl := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (pod ).Build ()
37+ cl := fake .NewClientBuilder ().
38+ WithScheme (scheme ).
39+ WithObjects (pod ).
40+ WithIndex (& corev1.Pod {}, "spec.nodeName" , func (obj client.Object ) []string {
41+ pod := obj .(* corev1.Pod )
42+ return []string {pod .Spec .NodeName }
43+ }).
44+ Build ()
3245 rater := NewTopologyRater (cl )
3346
3447 cfg := & gameKruiseV1alpha1.TopologyDeletionPriorityConfig {}
@@ -47,4 +60,3 @@ func TestTopologyRater_Basic(t *testing.T) {
4760 t .Fatalf ("unexpected priority: got=%d want=%d" , got .IntVal , 85 )
4861 }
4962}
50-
0 commit comments