github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/pkg/test/util.go (about) 1 /* 2 Copyright 2017 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 test 18 19 import ( 20 metav1 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/apis/meta/v1" 21 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/apis/testapigroup" 22 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/apis/testapigroup/v1" 23 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/runtime" 24 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/runtime/schema" 25 apiserializer "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/runtime/serializer" 26 utilruntime "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/util/runtime" 27 ) 28 29 // List and ListV1 should be kept in sync with k8s.io/kubernetes/pkg/api#List 30 // and k8s.io/api/core/v1#List. 31 // 32 // +k8s:deepcopy-gen=true 33 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 34 type List struct { 35 metav1.TypeMeta 36 metav1.ListMeta 37 38 Items []runtime.Object 39 } 40 41 // +k8s:deepcopy-gen=true 42 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 43 type ListV1 struct { 44 metav1.TypeMeta `json:",inline"` 45 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 46 47 Items []runtime.RawExtension `json:"items" protobuf:"bytes,2,rep,name=items"` 48 } 49 50 func TestScheme() (*runtime.Scheme, apiserializer.CodecFactory) { 51 internalGV := schema.GroupVersion{Group: "", Version: runtime.APIVersionInternal} 52 externalGV := schema.GroupVersion{Group: "", Version: "v1"} 53 scheme := runtime.NewScheme() 54 55 scheme.AddKnownTypes(internalGV, 56 &testapigroup.Carp{}, 57 &testapigroup.CarpList{}, 58 &List{}, 59 ) 60 scheme.AddKnownTypes(externalGV, 61 &v1.Carp{}, 62 &v1.CarpList{}, 63 &List{}, 64 ) 65 utilruntime.Must(testapigroup.AddToScheme(scheme)) 66 utilruntime.Must(v1.AddToScheme(scheme)) 67 68 codecs := apiserializer.NewCodecFactory(scheme) 69 return scheme, codecs 70 }