k8s.io/kubernetes@v1.29.3/pkg/apis/scheduling/v1/defaults_test.go (about) 1 /* 2 Copyright 2019 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v1_test 18 19 import ( 20 "reflect" 21 "testing" 22 23 apiv1 "k8s.io/api/core/v1" 24 v1 "k8s.io/api/scheduling/v1" 25 "k8s.io/apimachinery/pkg/runtime" 26 "k8s.io/kubernetes/pkg/api/legacyscheme" 27 28 // ensure types are installed 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(v1.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 TestSetDefaultPreemptionPolicy(t *testing.T) { 54 priorityClass := &v1.PriorityClass{} 55 56 output := roundTrip(t, runtime.Object(priorityClass)).(*v1.PriorityClass) 57 if output.PreemptionPolicy == nil || *output.PreemptionPolicy != apiv1.PreemptLowerPriority { 58 t.Errorf("Expected PriorityClass.PreemptionPolicy value: %+v\ngot: %+v\n", apiv1.PreemptLowerPriority, output.PreemptionPolicy) 59 } 60 }