...
1
16
17 package schedulinggates
18
19 import (
20 "testing"
21
22 "github.com/google/go-cmp/cmp"
23
24 v1 "k8s.io/api/core/v1"
25 "k8s.io/kubernetes/pkg/scheduler/framework"
26 st "k8s.io/kubernetes/pkg/scheduler/testing"
27 "k8s.io/kubernetes/test/utils/ktesting"
28 )
29
30 func TestPreEnqueue(t *testing.T) {
31 tests := []struct {
32 name string
33 pod *v1.Pod
34 want *framework.Status
35 }{
36 {
37 name: "pod does not carry scheduling gates",
38 pod: st.MakePod().Name("p").Obj(),
39 want: nil,
40 },
41 {
42 name: "pod carries scheduling gates",
43 pod: st.MakePod().Name("p").SchedulingGates([]string{"foo", "bar"}).Obj(),
44 want: framework.NewStatus(framework.UnschedulableAndUnresolvable, "waiting for scheduling gates: [foo bar]"),
45 },
46 }
47
48 for _, tt := range tests {
49 t.Run(tt.name, func(t *testing.T) {
50 _, ctx := ktesting.NewTestContext(t)
51 p, err := New(ctx, nil, nil)
52 if err != nil {
53 t.Fatalf("Creating plugin: %v", err)
54 }
55
56 got := p.(framework.PreEnqueuePlugin).PreEnqueue(ctx, tt.pod)
57 if diff := cmp.Diff(tt.want, got); diff != "" {
58 t.Errorf("unexpected status (-want, +got):\n%s", diff)
59 }
60 })
61 }
62 }
63
View as plain text