...
1
16
17 package v1beta1_test
18
19 import (
20 "reflect"
21 "testing"
22
23 apiv1 "k8s.io/api/core/v1"
24 "k8s.io/api/scheduling/v1beta1"
25 "k8s.io/apimachinery/pkg/runtime"
26 "k8s.io/kubernetes/pkg/api/legacyscheme"
27
28
29 _ "k8s.io/kubernetes/pkg/apis/scheduling/install"
30 )
31
32 func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
33 codec := legacyscheme.Codecs.LegacyCodec(v1beta1.SchemeGroupVersion)
34 data, err := runtime.Encode(codec, obj)
35 if err != nil {
36 t.Errorf("%v\n %#v", err, obj)
37 return nil
38 }
39 obj2, err := runtime.Decode(codec, data)
40 if err != nil {
41 t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
42 return nil
43 }
44 obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
45 err = legacyscheme.Scheme.Convert(obj2, obj3, nil)
46 if err != nil {
47 t.Errorf("%v\nSource: %#v", err, obj2)
48 return nil
49 }
50 return obj3
51 }
52
53 func TestSetDefaultPreempting(t *testing.T) {
54 priorityClass := &v1beta1.PriorityClass{}
55
56 output := roundTrip(t, runtime.Object(priorityClass)).(*v1beta1.PriorityClass)
57 if output.PreemptionPolicy == nil || *output.PreemptionPolicy != apiv1.PreemptLowerPriority {
58 t.Errorf("Expected PriorityClass.Preempting value: %+v\ngot: %+v\n", apiv1.PreemptLowerPriority, output.PreemptionPolicy)
59 }
60 }
61
View as plain text