mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-12-15 23:53:09 +00:00
feature(scheduler): implement ClusterEventWithHint to filter out useless events
This commit is contained in:
@@ -383,3 +383,107 @@ func TestPatchPodStatus(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Test_As tests the As function with Pod.
|
||||
func Test_As_Pod(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
oldObj interface{}
|
||||
newObj interface{}
|
||||
wantOldObj *v1.Pod
|
||||
wantNewObj *v1.Pod
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "nil old Pod",
|
||||
oldObj: nil,
|
||||
newObj: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||
wantOldObj: nil,
|
||||
wantNewObj: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||
},
|
||||
{
|
||||
name: "nil new Pod",
|
||||
oldObj: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||
newObj: nil,
|
||||
wantOldObj: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||
wantNewObj: nil,
|
||||
},
|
||||
{
|
||||
name: "two different kinds of objects",
|
||||
oldObj: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||
newObj: &v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
gotOld, gotNew, err := As[*v1.Pod](tc.oldObj, tc.newObj)
|
||||
if err != nil && !tc.wantErr {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if tc.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("expected error, but got nil")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(tc.wantOldObj, gotOld); diff != "" {
|
||||
t.Errorf("unexpected old object (-want,+got):\n%s", diff)
|
||||
}
|
||||
if diff := cmp.Diff(tc.wantNewObj, gotNew); diff != "" {
|
||||
t.Errorf("unexpected new object (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Test_As_Node tests the As function with Node.
|
||||
func Test_As_Node(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
oldObj interface{}
|
||||
newObj interface{}
|
||||
wantOldObj *v1.Node
|
||||
wantNewObj *v1.Node
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "nil old Node",
|
||||
oldObj: nil,
|
||||
newObj: &v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||
wantOldObj: nil,
|
||||
wantNewObj: &v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||
},
|
||||
{
|
||||
name: "nil new Node",
|
||||
oldObj: &v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||
newObj: nil,
|
||||
wantOldObj: &v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "foo"}},
|
||||
wantNewObj: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
gotOld, gotNew, err := As[*v1.Node](tc.oldObj, tc.newObj)
|
||||
if err != nil && !tc.wantErr {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if tc.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("expected error, but got nil")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(tc.wantOldObj, gotOld); diff != "" {
|
||||
t.Errorf("unexpected old object (-want,+got):\n%s", diff)
|
||||
}
|
||||
if diff := cmp.Diff(tc.wantNewObj, gotNew); diff != "" {
|
||||
t.Errorf("unexpected new object (-want,+got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user