@@ -5757,43 +5757,79 @@ func TestPrintLease(t *testing.T) {
5757
5757
}
5758
5758
5759
5759
func TestPrintPriorityClass (t * testing.T ) {
5760
+ preemptNever := api .PreemptNever
5761
+ preemptLowerPriority := api .PreemptLowerPriority
5760
5762
tests := []struct {
5763
+ name string
5764
+ options printers.GenerateOptions
5761
5765
pc scheduling.PriorityClass
5762
5766
expected []metav1.TableRow
5763
5767
}{
5764
5768
{
5769
+ name : "Test case with PreemptNever policy" ,
5765
5770
pc : scheduling.PriorityClass {
5766
5771
ObjectMeta : metav1.ObjectMeta {
5767
5772
Name : "pc1" ,
5768
5773
CreationTimestamp : metav1.Time {Time : time .Now ().Add (1.9e9 )},
5769
5774
},
5770
- Value : 1 ,
5775
+ Value : 1 ,
5776
+ PreemptionPolicy : & preemptNever ,
5771
5777
},
5772
5778
expected : []metav1.TableRow {{Cells : []interface {}{"pc1" , int64 (1 ), bool (false ), "0s" }}},
5773
5779
},
5774
5780
{
5781
+ name : "Test case with PreemptLowerPriority policy" ,
5775
5782
pc : scheduling.PriorityClass {
5776
5783
ObjectMeta : metav1.ObjectMeta {
5777
5784
Name : "pc2" ,
5778
5785
CreationTimestamp : metav1.Time {Time : time .Now ().Add (- 3e11 )},
5779
5786
},
5780
- Value : 1000000000 ,
5781
- GlobalDefault : true ,
5787
+ Value : 1000000000 ,
5788
+ GlobalDefault : true ,
5789
+ PreemptionPolicy : & preemptLowerPriority ,
5782
5790
},
5783
5791
expected : []metav1.TableRow {{Cells : []interface {}{"pc2" , int64 (1000000000 ), bool (true ), "5m" }}},
5784
5792
},
5793
+ {
5794
+ name : "Test case with PreemptLowerPriority policy and wide output" ,
5795
+ options : printers.GenerateOptions {Wide : true },
5796
+ pc : scheduling.PriorityClass {
5797
+ ObjectMeta : metav1.ObjectMeta {
5798
+ Name : "pc2" ,
5799
+ CreationTimestamp : metav1.Time {Time : time .Now ().Add (- 3e11 )},
5800
+ },
5801
+ Value : 1000000000 ,
5802
+ GlobalDefault : true ,
5803
+ PreemptionPolicy : & preemptLowerPriority ,
5804
+ },
5805
+ expected : []metav1.TableRow {{Cells : []interface {}{"pc2" , int64 (1000000000 ), bool (true ), "5m" , string (api .PreemptLowerPriority )}}},
5806
+ },
5807
+ {
5808
+ name : "Test case without set PreemptLowerPriority policy" ,
5809
+ options : printers.GenerateOptions {Wide : true },
5810
+ pc : scheduling.PriorityClass {
5811
+ ObjectMeta : metav1.ObjectMeta {
5812
+ Name : "pc2" ,
5813
+ CreationTimestamp : metav1.Time {Time : time .Now ().Add (- 3e11 )},
5814
+ },
5815
+ Value : 1000000000 ,
5816
+ GlobalDefault : true ,
5817
+ PreemptionPolicy : nil ,
5818
+ },
5819
+ expected : []metav1.TableRow {{Cells : []interface {}{"pc2" , int64 (1000000000 ), bool (true ), "5m" , string ("" )}}},
5820
+ },
5785
5821
}
5786
5822
5787
5823
for i , test := range tests {
5788
- rows , err := printPriorityClass (& test .pc , printers. GenerateOptions {} )
5824
+ rows , err := printPriorityClass (& test .pc , test . options )
5789
5825
if err != nil {
5790
5826
t .Fatal (err )
5791
5827
}
5792
5828
for i := range rows {
5793
5829
rows [i ].Object .Object = nil
5794
5830
}
5795
5831
if ! reflect .DeepEqual (test .expected , rows ) {
5796
- t .Errorf ("% d mismatch: %s" , i , cmp .Diff (test .expected , rows ))
5832
+ t .Errorf ("test case %s: % d mismatch: %s" , test . name , i , cmp .Diff (test .expected , rows ))
5797
5833
}
5798
5834
}
5799
5835
}
0 commit comments