apimachinery+apiserver: extract test types to work w/ deepcopy-gen
Kubernetes-commit: 205cd90d465b7287fdad5f77d1dc4ac13624b067
This commit is contained in:
parent
8304eb8a20
commit
15712b92c3
|
@ -174,30 +174,21 @@ func addGrouplessTypes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func addTestTypes() {
|
func addTestTypes() {
|
||||||
type ListOptions struct {
|
|
||||||
Object runtime.Object
|
|
||||||
metav1.TypeMeta `json:",inline"`
|
|
||||||
LabelSelector string `json:"labelSelector,omitempty"`
|
|
||||||
FieldSelector string `json:"fieldSelector,omitempty"`
|
|
||||||
Watch bool `json:"watch,omitempty"`
|
|
||||||
ResourceVersion string `json:"resourceVersion,omitempty"`
|
|
||||||
TimeoutSeconds *int64 `json:"timeoutSeconds,omitempty"`
|
|
||||||
}
|
|
||||||
scheme.AddKnownTypes(testGroupVersion,
|
scheme.AddKnownTypes(testGroupVersion,
|
||||||
&genericapitesting.Simple{}, &genericapitesting.SimpleList{}, &metav1.ExportOptions{},
|
&genericapitesting.Simple{}, &genericapitesting.SimpleList{}, &metav1.ExportOptions{},
|
||||||
&metav1.DeleteOptions{}, &genericapitesting.SimpleGetOptions{}, &genericapitesting.SimpleRoot{},
|
&metav1.DeleteOptions{}, &genericapitesting.SimpleGetOptions{}, &genericapitesting.SimpleRoot{},
|
||||||
&SimpleXGSubresource{})
|
&genericapitesting.SimpleXGSubresource{})
|
||||||
scheme.AddKnownTypes(testGroupVersion, &examplev1.Pod{})
|
scheme.AddKnownTypes(testGroupVersion, &examplev1.Pod{})
|
||||||
scheme.AddKnownTypes(testInternalGroupVersion,
|
scheme.AddKnownTypes(testInternalGroupVersion,
|
||||||
&genericapitesting.Simple{}, &genericapitesting.SimpleList{}, &metav1.ExportOptions{},
|
&genericapitesting.Simple{}, &genericapitesting.SimpleList{}, &metav1.ExportOptions{},
|
||||||
&genericapitesting.SimpleGetOptions{}, &genericapitesting.SimpleRoot{},
|
&genericapitesting.SimpleGetOptions{}, &genericapitesting.SimpleRoot{},
|
||||||
&SimpleXGSubresource{})
|
&genericapitesting.SimpleXGSubresource{})
|
||||||
scheme.AddKnownTypes(testInternalGroupVersion, &example.Pod{})
|
scheme.AddKnownTypes(testInternalGroupVersion, &example.Pod{})
|
||||||
// Register SimpleXGSubresource in both testGroupVersion and testGroup2Version, and also their
|
// Register SimpleXGSubresource in both testGroupVersion and testGroup2Version, and also their
|
||||||
// their corresponding internal versions, to verify that the desired group version object is
|
// their corresponding internal versions, to verify that the desired group version object is
|
||||||
// served in the tests.
|
// served in the tests.
|
||||||
scheme.AddKnownTypes(testGroup2Version, &SimpleXGSubresource{}, &metav1.ExportOptions{})
|
scheme.AddKnownTypes(testGroup2Version, &genericapitesting.SimpleXGSubresource{}, &metav1.ExportOptions{})
|
||||||
scheme.AddKnownTypes(testInternalGroup2Version, &SimpleXGSubresource{}, &metav1.ExportOptions{})
|
scheme.AddKnownTypes(testInternalGroup2Version, &genericapitesting.SimpleXGSubresource{}, &metav1.ExportOptions{})
|
||||||
metav1.AddToGroupVersion(scheme, testGroupVersion)
|
metav1.AddToGroupVersion(scheme, testGroupVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1153,10 +1144,10 @@ func TestList(t *testing.T) {
|
||||||
t.Errorf("%d: %q unexpected resource namespace: %s", i, testCase.url, simpleStorage.actualNamespace)
|
t.Errorf("%d: %q unexpected resource namespace: %s", i, testCase.url, simpleStorage.actualNamespace)
|
||||||
}
|
}
|
||||||
if simpleStorage.requestedLabelSelector == nil || simpleStorage.requestedLabelSelector.String() != testCase.label {
|
if simpleStorage.requestedLabelSelector == nil || simpleStorage.requestedLabelSelector.String() != testCase.label {
|
||||||
t.Errorf("%d: unexpected label selector: %v", i, simpleStorage.requestedLabelSelector)
|
t.Errorf("%d: unexpected label selector: expected=%v got=%v", i, testCase.label, simpleStorage.requestedLabelSelector)
|
||||||
}
|
}
|
||||||
if simpleStorage.requestedFieldSelector == nil || simpleStorage.requestedFieldSelector.String() != testCase.field {
|
if simpleStorage.requestedFieldSelector == nil || simpleStorage.requestedFieldSelector.String() != testCase.field {
|
||||||
t.Errorf("%d: unexpected field selector: %v", i, simpleStorage.requestedFieldSelector)
|
t.Errorf("%d: unexpected field selector: expected=%v got=%v", i, testCase.field, simpleStorage.requestedFieldSelector)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3935,23 +3926,12 @@ func TestUpdateChecksAPIVersion(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SimpleXGSubresource is a cross group subresource, i.e. the subresource does not belong to the
|
|
||||||
// same group as its parent resource.
|
|
||||||
type SimpleXGSubresource struct {
|
|
||||||
metav1.TypeMeta `json:",inline"`
|
|
||||||
metav1.ObjectMeta `json:"metadata"`
|
|
||||||
SubresourceInfo string `json:"subresourceInfo,omitempty"`
|
|
||||||
Labels map[string]string `json:"labels,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (obj *SimpleXGSubresource) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
|
|
||||||
|
|
||||||
type SimpleXGSubresourceRESTStorage struct {
|
type SimpleXGSubresourceRESTStorage struct {
|
||||||
item SimpleXGSubresource
|
item genericapitesting.SimpleXGSubresource
|
||||||
}
|
}
|
||||||
|
|
||||||
func (storage *SimpleXGSubresourceRESTStorage) New() runtime.Object {
|
func (storage *SimpleXGSubresourceRESTStorage) New() runtime.Object {
|
||||||
return &SimpleXGSubresource{}
|
return &genericapitesting.SimpleXGSubresource{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (storage *SimpleXGSubresourceRESTStorage) Get(ctx request.Context, id string, options *metav1.GetOptions) (runtime.Object, error) {
|
func (storage *SimpleXGSubresourceRESTStorage) Get(ctx request.Context, id string, options *metav1.GetOptions) (runtime.Object, error) {
|
||||||
|
@ -3969,7 +3949,7 @@ func TestXGSubresource(t *testing.T) {
|
||||||
|
|
||||||
itemID := "theID"
|
itemID := "theID"
|
||||||
subresourceStorage := &SimpleXGSubresourceRESTStorage{
|
subresourceStorage := &SimpleXGSubresourceRESTStorage{
|
||||||
item: SimpleXGSubresource{
|
item: genericapitesting.SimpleXGSubresource{
|
||||||
SubresourceInfo: "foo",
|
SubresourceInfo: "foo",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -4018,7 +3998,7 @@ func TestXGSubresource(t *testing.T) {
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
t.Fatalf("unexpected response: %#v", resp)
|
t.Fatalf("unexpected response: %#v", resp)
|
||||||
}
|
}
|
||||||
var itemOut SimpleXGSubresource
|
var itemOut genericapitesting.SimpleXGSubresource
|
||||||
body, err := extractBody(resp, &itemOut)
|
body, err := extractBody(resp, &itemOut)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -4030,7 +4010,7 @@ func TestXGSubresource(t *testing.T) {
|
||||||
// conversion type list in API scheme and hence cannot be converted from input type object
|
// conversion type list in API scheme and hence cannot be converted from input type object
|
||||||
// to output type object. So it's values don't appear in the decoded output object.
|
// to output type object. So it's values don't appear in the decoded output object.
|
||||||
decoder := json.NewDecoder(strings.NewReader(body))
|
decoder := json.NewDecoder(strings.NewReader(body))
|
||||||
var itemFromBody SimpleXGSubresource
|
var itemFromBody genericapitesting.SimpleXGSubresource
|
||||||
err = decoder.Decode(&itemFromBody)
|
err = decoder.Decode(&itemFromBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected JSON decoding error: %v", err)
|
t.Errorf("unexpected JSON decoding error: %v", err)
|
||||||
|
|
|
@ -25,27 +25,9 @@ import (
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
openapitesting "k8s.io/apiserver/pkg/endpoints/openapi/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestType struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t TestType) GetObjectKind() schema.ObjectKind {
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t TestType) SetGroupVersionKind(kind schema.GroupVersionKind) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t TestType) GroupVersionKind() schema.GroupVersionKind {
|
|
||||||
return schema.GroupVersionKind{
|
|
||||||
Group: "test",
|
|
||||||
Version: "v1",
|
|
||||||
Kind: "TestType",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func assertEqual(t *testing.T, expected, actual interface{}) {
|
func assertEqual(t *testing.T, expected, actual interface{}) {
|
||||||
var equal bool
|
var equal bool
|
||||||
if expected == nil || actual == nil {
|
if expected == nil || actual == nil {
|
||||||
|
@ -59,17 +41,17 @@ func assertEqual(t *testing.T, expected, actual interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetDefinitionName(t *testing.T) {
|
func TestGetDefinitionName(t *testing.T) {
|
||||||
testType := TestType{}
|
testType := openapitesting.TestType{}
|
||||||
// in production, the name is stripped of ".*vendor/" prefix before passed
|
// in production, the name is stripped of ".*vendor/" prefix before passed
|
||||||
// to GetDefinitionName, so here typePkgName does not have the
|
// to GetDefinitionName, so here typePkgName does not have the
|
||||||
// "k8s.io/kubernetes/vendor" prefix.
|
// "k8s.io/kubernetes/vendor" prefix.
|
||||||
typePkgName := "k8s.io/apiserver/pkg/endpoints/openapi.TestType"
|
typePkgName := "k8s.io/apiserver/pkg/endpoints/openapi/testing.TestType"
|
||||||
typeFriendlyName := "io.k8s.apiserver.pkg.endpoints.openapi.TestType"
|
typeFriendlyName := "io.k8s.apiserver.pkg.endpoints.openapi.testing.TestType"
|
||||||
if strings.HasSuffix(reflect.TypeOf(testType).PkgPath(), "go_default_test") {
|
if strings.HasSuffix(reflect.TypeOf(testType).PkgPath(), "go_default_test") {
|
||||||
// the test is running inside bazel where the package name is changed and
|
// the test is running inside bazel where the package name is changed and
|
||||||
// "go_default_test" will add to package path.
|
// "go_default_test" will add to package path.
|
||||||
typePkgName = "k8s.io/apiserver/pkg/endpoints/openapi/go_default_test.TestType"
|
typePkgName = "k8s.io/apiserver/pkg/endpoints/openapi/testing/go_default_test.TestType"
|
||||||
typeFriendlyName = "io.k8s.apiserver.pkg.endpoints.openapi.go_default_test.TestType"
|
typeFriendlyName = "io.k8s.apiserver.pkg.endpoints.openapi.testing.go_default_test.TestType"
|
||||||
}
|
}
|
||||||
s := runtime.NewScheme()
|
s := runtime.NewScheme()
|
||||||
s.AddKnownTypeWithName(testType.GroupVersionKind(), &testType)
|
s.AddKnownTypeWithName(testType.GroupVersionKind(), &testType)
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
Copyright 2016 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package testing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=true
|
||||||
|
type TestType struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t TestType) GetObjectKind() schema.ObjectKind {
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t TestType) SetGroupVersionKind(kind schema.GroupVersionKind) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t TestType) GroupVersionKind() schema.GroupVersionKind {
|
||||||
|
return schema.GroupVersionKind{
|
||||||
|
Group: "test",
|
||||||
|
Version: "v1",
|
||||||
|
Kind: "TestType",
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
// +build !ignore_autogenerated
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2017 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This file was autogenerated by deepcopy-gen. Do not edit it manually!
|
||||||
|
|
||||||
|
package testing
|
||||||
|
|
||||||
|
import (
|
||||||
|
conversion "k8s.io/apimachinery/pkg/conversion"
|
||||||
|
reflect "reflect"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
|
||||||
|
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
|
||||||
|
return []conversion.GeneratedDeepCopyFunc{
|
||||||
|
{Fn: DeepCopy_openapi_TestType, InType: reflect.TypeOf(&TestType{})},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeepCopy_openapi_TestType is an autogenerated deepcopy function.
|
||||||
|
func DeepCopy_openapi_TestType(in interface{}, out interface{}, c *conversion.Cloner) error {
|
||||||
|
{
|
||||||
|
in := in.(*TestType)
|
||||||
|
out := out.(*TestType)
|
||||||
|
*out = *in
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
Copyright 2017 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=package
|
||||||
|
|
||||||
|
package testing // import "k8s.io/apiserver/pkg/endpoints/testing"
|
|
@ -67,3 +67,14 @@ type SimpleList struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj *SimpleList) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
|
func (obj *SimpleList) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
|
||||||
|
|
||||||
|
// SimpleXGSubresource is a cross group subresource, i.e. the subresource does not belong to the
|
||||||
|
// same group as its parent resource.
|
||||||
|
type SimpleXGSubresource struct {
|
||||||
|
metav1.TypeMeta `json:",inline"`
|
||||||
|
metav1.ObjectMeta `json:"metadata"`
|
||||||
|
SubresourceInfo string `json:"subresourceInfo,omitempty"`
|
||||||
|
Labels map[string]string `json:"labels,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (obj *SimpleXGSubresource) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
Copyright 2015 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=package
|
||||||
|
|
||||||
|
package testing
|
Loading…
Reference in New Issue