...
1
16
17 package v1
18
19 import (
20 "testing"
21
22 v1 "k8s.io/api/scheduling/v1"
23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24 "k8s.io/kubernetes/pkg/apis/scheduling"
25 )
26
27 func TestIsKnownSystemPriorityClass(t *testing.T) {
28 tests := []struct {
29 name string
30 pc *v1.PriorityClass
31 expected bool
32 }{
33 {
34 name: "system priority class",
35 pc: SystemPriorityClasses()[0],
36 expected: true,
37 },
38 {
39 name: "non-system priority class",
40 pc: &v1.PriorityClass{
41 ObjectMeta: metav1.ObjectMeta{
42 Name: scheduling.SystemNodeCritical,
43 },
44 Value: scheduling.SystemCriticalPriority,
45 Description: "Used for system critical pods that must not be moved from their current node.",
46 },
47 expected: false,
48 },
49 {
50 name: "not a known system priority class",
51 pc: &v1.PriorityClass{
52 ObjectMeta: metav1.ObjectMeta{
53 Name: "unknown",
54 },
55 Value: scheduling.SystemCriticalPriority,
56 Description: "Used for system critical pods that must run in the cluster, but can be moved to another node if necessary.",
57 },
58 expected: false,
59 },
60 {
61 name: "global default changed",
62 pc: &v1.PriorityClass{
63 ObjectMeta: metav1.ObjectMeta{
64 Name: scheduling.SystemClusterCritical,
65 },
66 GlobalDefault: true,
67 Value: scheduling.SystemCriticalPriority,
68 Description: "Used for system critical pods that must run in the cluster, but can be moved to another node if necessary.",
69 },
70 expected: false,
71 },
72 }
73
74 for _, test := range tests {
75 if is, err := IsKnownSystemPriorityClass(test.pc.Name, test.pc.Value, test.pc.GlobalDefault); test.expected != is {
76 t.Errorf("Test [%v]: Expected %v, but got %v. Error: %v", test.name, test.expected, is, err)
77 }
78 }
79 }
80
View as plain text