...
1
16
17 package priorityclass
18
19 import (
20 "testing"
21
22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23 genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
24 "k8s.io/kubernetes/pkg/apis/scheduling"
25 )
26
27 func TestPriorityClassStrategy(t *testing.T) {
28 ctx := genericapirequest.NewDefaultContext()
29 if Strategy.NamespaceScoped() {
30 t.Errorf("PriorityClass must not be namespace scoped")
31 }
32 if Strategy.AllowCreateOnUpdate() {
33 t.Errorf("PriorityClass should not allow create on update")
34 }
35
36 priorityClass := &scheduling.PriorityClass{
37 ObjectMeta: metav1.ObjectMeta{
38 Name: "valid-class",
39 },
40 Value: 10,
41 }
42
43 Strategy.PrepareForCreate(ctx, priorityClass)
44
45 errs := Strategy.Validate(ctx, priorityClass)
46 if len(errs) != 0 {
47 t.Errorf("unexpected error validating %v", errs)
48 }
49
50 newPriorityClass := &scheduling.PriorityClass{
51 ObjectMeta: metav1.ObjectMeta{
52 Name: "valid-class-2",
53 ResourceVersion: "4",
54 },
55 Value: 20,
56 }
57
58 Strategy.PrepareForUpdate(ctx, newPriorityClass, priorityClass)
59
60 errs = Strategy.ValidateUpdate(ctx, newPriorityClass, priorityClass)
61 if len(errs) == 0 {
62 t.Errorf("Expected a validation error")
63 }
64 }
65
View as plain text