MCPcopy
hub / github.com/kubernetes/kubernetes / TestAddPod

Function TestAddPod

pkg/scheduler/eventhandlers_test.go:830–883  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

828}
829
830func TestAddPod(t *testing.T) {
831 tests := []struct {
832 name string
833 pod *v1.Pod
834 expectInQueue bool
835 expectInCache bool
836 }{
837 {
838 name: "add unscheduled pod",
839 pod: st.MakePod().Name("pod1").Namespace("ns1").UID("pod1").SchedulerName("supported-scheduler").Obj(),
840 expectInQueue: true,
841 },
842 {
843 name: "add unscheduled pod with other scheduler name",
844 pod: st.MakePod().Name("pod1").Namespace("ns1").UID("pod1").SchedulerName("other-scheduler").Obj(),
845 },
846 {
847 name: "add scheduled pod",
848 pod: st.MakePod().Name("pod1").Namespace("ns1").UID("pod1").Node("node1").Obj(),
849 expectInCache: true,
850 },
851 }
852 for _, tt := range tests {
853 t.Run(tt.name, func(t *testing.T) {
854 logger, ctx := ktesting.NewTestContext(t)
855 ctx, cancel := context.WithCancel(ctx)
856 defer cancel()
857
858 sched := &Scheduler{
859 Cache: internalcache.New(ctx, nil, false),
860 SchedulingQueue: internalqueue.NewTestQueue(ctx, nil),
861 logger: logger,
862 Profiles: profile.Map{
863 "supported-scheduler": nil,
864 },
865 }
866
867 sched.addPod(tt.pod)
868
869 _, ok := sched.SchedulingQueue.GetPod(tt.pod.Name, tt.pod.Namespace)
870 if tt.expectInQueue && !ok {
871 t.Errorf("Expected pod to be in scheduling queue")
872 } else if !tt.expectInQueue && ok {
873 t.Errorf("Expected pod not to be in scheduling queue")
874 }
875 _, err := sched.Cache.GetPod(tt.pod)
876 if tt.expectInCache && err != nil {
877 t.Errorf("Expected pod to be in cache: %v", err)
878 } else if !tt.expectInCache && err == nil {
879 t.Errorf("Expected pod not to be in cache")
880 }
881 })
882 }
883}
884
885func TestUpdatePod(t *testing.T) {
886 pod := st.MakePod().Name("pod1").Namespace("ns1").UID("pod1").SchedulerName("supported-scheduler").Obj()

Callers

nothing calls this directly

Calls 12

addPodMethod · 0.95
WithCancelMethod · 0.80
ObjMethod · 0.65
SchedulerNameMethod · 0.65
UIDMethod · 0.65
NamespaceMethod · 0.65
NameMethod · 0.65
NodeMethod · 0.65
RunMethod · 0.65
NewMethod · 0.65
GetPodMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…