Repository: kubernetes/kubernetes
File: pkg/scheduler/framework/plugins/defaultpreemption/default_preemption_test.go (Go)

Code before:
	if expectedNode != result.NominatedNodeName {
		t.Errorf("expected NodeName %q, got %q", expectedNode, result.NominatedNodeName)
	}
	if len(result.Victims) != len(expectedVictims) {
		t.Errorf("expected %d victims, got %d", len(expectedVictims), len(result.Victims))
	}
	for _, victim := range result.Victims {
		if !expectedVictims.Has(victim.Name) {
			t.Errorf("pod %v is not expected to be a victim.", victim.Name)
		}
	}
}

func TestPostFilter(t *testing.T) {
	onePodRes := map[v1.ResourceName]string{v1.ResourcePods: "1"}
	nodeRes := map[v1.ResourceName]string{v1.ResourceCPU: "200m", v1.ResourceMemory: "400"}
	tests := []struct {
		name                    string
		pod                     *v1.Pod
		pods                    []*v1.Pod
		pdbs                    []*policy.PodDisruptionBudget
		nodes                   []*v1.Node
		filteredNodesStatuses   *framework.NodeToStatus
		extender                fwk.Extender
		wantNilPostFilterResult bool
		expectedPods            sets.Set[string] // set of preempted pods
		expectedNode            string           // nominated node name for the preemptor
		wantStatus              *fwk.Status
	}{
		{
			name: "pod with higher priority can be made schedulable",
			pod:  st.MakePod().Name("p").UID("p").Namespace(v1.NamespaceDefault).Priority(highPriority).Obj(),
			pods: []*v1.Pod{
				st.MakePod().Name("p1").UID("p1").Namespace(v1.NamespaceDefault).Node("node1").Obj(),
			},
			nodes: []*v1.Node{
				st.MakeNode().Name("node1").Capacity(onePodRes).Obj(),
			},
			filteredNodesStatuses: framework.NewNodeToStatus(map[string]*fwk.Status{
				"node1": fwk.NewStatus(fwk.Unschedulable),
			}, fwk.NewStatus(fwk.UnschedulableAndUnresolvable)),
			expectedNode: "node1",
			expectedPods: sets.New("p1"),
			wantStatus:   fwk.NewStatus(fwk.Success),
		},
		{
			name: "pod with tied priority is still unschedulable",
			pod:  st.MakePod().Name("p").UID("p").Namespace(v1.NamespaceDefault).Obj(),
			pods: []*v1.Pod{
				st.MakePod().Name("p1").UID("p1").Namespace(v1.NamespaceDefault).Node("node1").Obj(),
			},

Review comment (suggestion):
```suggestion
		expectedVictims            sets.Set[string]
```
use self-explanatory names instead of comments

Code after:
	if expectedNode != result.NominatedNodeName {
		t.Errorf("expected NodeName %q, got %q", expectedNode, result.NominatedNodeName)
	}
	if len(result.Victims) != len(expectedVictims) {
		t.Errorf("expected %d victims, got %d", len(expectedVictims), len(result.Victims))
	}
	for _, victim := range result.Victims {
		if !expectedVictims.Has(victim.Name) {
			t.Errorf("pod %v is not expected to be a victim.", victim.Name)
		}
	}
}

func TestPostFilter(t *testing.T) {
	onePodRes := map[v1.ResourceName]string{v1.ResourcePods: "1"}
	nodeRes := map[v1.ResourceName]string{v1.ResourceCPU: "200m", v1.ResourceMemory: "400"}
	tests := []struct {
		name                    string
		pod                     *v1.Pod
		pods                    []*v1.Pod
		pdbs                    []*policy.PodDisruptionBudget
		nodes                   []*v1.Node
		filteredNodesStatuses   *framework.NodeToStatus
		extender                fwk.Extender
		wantNilPostFilterResult bool
		expectedVictims         sets.Set[string]
		expectedNominatedNode   string
		wantStatus              *fwk.Status
	}{
		{
			name: "pod with higher priority can be made schedulable",
			pod:  st.MakePod().Name("p").UID("p").Namespace(v1.NamespaceDefault).Priority(highPriority).Obj(),
			pods: []*v1.Pod{
				st.MakePod().Name("p1").UID("p1").Namespace(v1.NamespaceDefault).Node("node1").Obj(),
			},
			nodes: []*v1.Node{
				st.MakeNode().Name("node1").Capacity(onePodRes).Obj(),
			},
			filteredNodesStatuses: framework.NewNodeToStatus(map[string]*fwk.Status{
				"node1": fwk.NewStatus(fwk.Unschedulable),
			}, fwk.NewStatus(fwk.UnschedulableAndUnresolvable)),
			expectedNominatedNode: "node1",
			expectedVictims:       sets.New("p1"),
			wantStatus:            fwk.NewStatus(fwk.Success),
		},
		{
			name: "pod with tied priority is still unschedulable",
			pod:  st.MakePod().Name("p").UID("p").Namespace(v1.NamespaceDefault).Obj(),
			pods: []*v1.Pod{
				st.MakePod().Name("p1").UID("p1").Namespace(v1.NamespaceDefault).Node("node1").Obj(),
			},