(t *testing.T)
| 828 | } |
| 829 | |
| 830 | func 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 | |
| 885 | func TestUpdatePod(t *testing.T) { |
| 886 | pod := st.MakePod().Name("pod1").Namespace("ns1").UID("pod1").SchedulerName("supported-scheduler").Obj() |
nothing calls this directly
no test coverage detected
searching dependent graphs…