Skip to content

Commit 70fa697

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#48601 from sttts/sttts-separate-test-types
Automatic merge from submit-queue (batch tested with PRs 48583, 48605, 48601) apimachinery+apiserver: separate test types in their own packages Preparation for static deepcopy kubernetes#48544 and its use of package-global deepcopy-gen tags for all runtime.Objects. - [x] wait for kubernetes#48497
2 parents eab5e06 + d358cb1 commit 70fa697

31 files changed

+2030
-540
lines changed

staging/src/k8s.io/apiextensions-apiserver/examples/client-go/apis/cr/v1/BUILD

+3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ go_test(
2525
go_library(
2626
name = "go_default_library",
2727
srcs = [
28+
"doc.go",
2829
"register.go",
2930
"types.go",
31+
"zz_generated.deepcopy.go",
3032
],
3133
tags = ["automanaged"],
3234
deps = [
3335
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
36+
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
3437
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
3538
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
3639
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
// +k8s:deepcopy-gen=package
18+
package v1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// +build !ignore_autogenerated
2+
3+
/*
4+
Copyright 2017 The Kubernetes Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
// This file was autogenerated by deepcopy-gen. Do not edit it manually!
20+
21+
package v1
22+
23+
import (
24+
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
conversion "k8s.io/apimachinery/pkg/conversion"
26+
reflect "reflect"
27+
)
28+
29+
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
30+
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
31+
return []conversion.GeneratedDeepCopyFunc{
32+
{Fn: DeepCopy_v1_Example, InType: reflect.TypeOf(&Example{})},
33+
{Fn: DeepCopy_v1_ExampleList, InType: reflect.TypeOf(&ExampleList{})},
34+
{Fn: DeepCopy_v1_ExampleSpec, InType: reflect.TypeOf(&ExampleSpec{})},
35+
{Fn: DeepCopy_v1_ExampleStatus, InType: reflect.TypeOf(&ExampleStatus{})},
36+
}
37+
}
38+
39+
// DeepCopy_v1_Example is an autogenerated deepcopy function.
40+
func DeepCopy_v1_Example(in interface{}, out interface{}, c *conversion.Cloner) error {
41+
{
42+
in := in.(*Example)
43+
out := out.(*Example)
44+
*out = *in
45+
if newVal, err := c.DeepCopy(&in.ObjectMeta); err != nil {
46+
return err
47+
} else {
48+
out.ObjectMeta = *newVal.(*meta_v1.ObjectMeta)
49+
}
50+
return nil
51+
}
52+
}
53+
54+
// DeepCopy_v1_ExampleList is an autogenerated deepcopy function.
55+
func DeepCopy_v1_ExampleList(in interface{}, out interface{}, c *conversion.Cloner) error {
56+
{
57+
in := in.(*ExampleList)
58+
out := out.(*ExampleList)
59+
*out = *in
60+
if in.Items != nil {
61+
in, out := &in.Items, &out.Items
62+
*out = make([]Example, len(*in))
63+
for i := range *in {
64+
if newVal, err := c.DeepCopy(&(*in)[i]); err != nil {
65+
return err
66+
} else {
67+
(*out)[i] = *newVal.(*Example)
68+
}
69+
}
70+
}
71+
return nil
72+
}
73+
}
74+
75+
// DeepCopy_v1_ExampleSpec is an autogenerated deepcopy function.
76+
func DeepCopy_v1_ExampleSpec(in interface{}, out interface{}, c *conversion.Cloner) error {
77+
{
78+
in := in.(*ExampleSpec)
79+
out := out.(*ExampleSpec)
80+
*out = *in
81+
return nil
82+
}
83+
}
84+
85+
// DeepCopy_v1_ExampleStatus is an autogenerated deepcopy function.
86+
func DeepCopy_v1_ExampleStatus(in interface{}, out interface{}, c *conversion.Cloner) error {
87+
{
88+
in := in.(*ExampleStatus)
89+
out := out.(*ExampleStatus)
90+
*out = *in
91+
return nil
92+
}
93+
}

staging/src/k8s.io/apimachinery/pkg/runtime/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ go_test(
6363
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
6464
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
6565
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
66+
"//vendor/k8s.io/apimachinery/pkg/runtime/testing:go_default_library",
6667
"//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library",
6768
],
6869
)

staging/src/k8s.io/apimachinery/pkg/runtime/conversion_test.go

+13-33
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,17 @@ import (
2222

2323
"k8s.io/apimachinery/pkg/runtime"
2424
"k8s.io/apimachinery/pkg/runtime/schema"
25+
runtimetesting "k8s.io/apimachinery/pkg/runtime/testing"
2526
)
2627

27-
type InternalComplex struct {
28-
runtime.TypeMeta
29-
String string
30-
Integer int
31-
Integer64 int64
32-
Int64 int64
33-
Bool bool
34-
}
35-
36-
type ExternalComplex struct {
37-
runtime.TypeMeta `json:",inline"`
38-
String string `json:"string" description:"testing"`
39-
Integer int `json:"int"`
40-
Integer64 int64 `json:",omitempty"`
41-
Int64 int64
42-
Bool bool `json:"bool"`
43-
}
44-
45-
func (obj *InternalComplex) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
46-
func (obj *ExternalComplex) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }
47-
4828
func TestStringMapConversion(t *testing.T) {
4929
internalGV := schema.GroupVersion{Group: "test.group", Version: runtime.APIVersionInternal}
5030
externalGV := schema.GroupVersion{Group: "test.group", Version: "external"}
5131

5232
scheme := runtime.NewScheme()
5333
scheme.Log(t)
54-
scheme.AddKnownTypeWithName(internalGV.WithKind("Complex"), &InternalComplex{})
55-
scheme.AddKnownTypeWithName(externalGV.WithKind("Complex"), &ExternalComplex{})
34+
scheme.AddKnownTypeWithName(internalGV.WithKind("Complex"), &runtimetesting.InternalComplex{})
35+
scheme.AddKnownTypeWithName(externalGV.WithKind("Complex"), &runtimetesting.ExternalComplex{})
5636

5737
testCases := map[string]struct {
5838
input map[string][]string
@@ -66,62 +46,62 @@ func TestStringMapConversion(t *testing.T) {
6646
"int": {"1"},
6747
"Integer64": {"2"},
6848
},
69-
expected: &ExternalComplex{String: "value", Integer: 1},
49+
expected: &runtimetesting.ExternalComplex{String: "value", Integer: 1},
7050
},
7151
"returns error on bad int": {
7252
input: map[string][]string{
7353
"int": {"a"},
7454
},
7555
errFn: func(err error) bool { return err != nil },
76-
expected: &ExternalComplex{},
56+
expected: &runtimetesting.ExternalComplex{},
7757
},
7858
"parses int64": {
7959
input: map[string][]string{
8060
"Int64": {"-1"},
8161
},
82-
expected: &ExternalComplex{Int64: -1},
62+
expected: &runtimetesting.ExternalComplex{Int64: -1},
8363
},
8464
"returns error on bad int64": {
8565
input: map[string][]string{
8666
"Int64": {"a"},
8767
},
8868
errFn: func(err error) bool { return err != nil },
89-
expected: &ExternalComplex{},
69+
expected: &runtimetesting.ExternalComplex{},
9070
},
9171
"parses boolean true": {
9272
input: map[string][]string{
9373
"bool": {"true"},
9474
},
95-
expected: &ExternalComplex{Bool: true},
75+
expected: &runtimetesting.ExternalComplex{Bool: true},
9676
},
9777
"parses boolean any value": {
9878
input: map[string][]string{
9979
"bool": {"foo"},
10080
},
101-
expected: &ExternalComplex{Bool: true},
81+
expected: &runtimetesting.ExternalComplex{Bool: true},
10282
},
10383
"parses boolean false": {
10484
input: map[string][]string{
10585
"bool": {"false"},
10686
},
107-
expected: &ExternalComplex{Bool: false},
87+
expected: &runtimetesting.ExternalComplex{Bool: false},
10888
},
10989
"parses boolean empty value": {
11090
input: map[string][]string{
11191
"bool": {""},
11292
},
113-
expected: &ExternalComplex{Bool: true},
93+
expected: &runtimetesting.ExternalComplex{Bool: true},
11494
},
11595
"parses boolean no value": {
11696
input: map[string][]string{
11797
"bool": {},
11898
},
119-
expected: &ExternalComplex{Bool: false},
99+
expected: &runtimetesting.ExternalComplex{Bool: false},
120100
},
121101
}
122102

123103
for k, tc := range testCases {
124-
out := &ExternalComplex{}
104+
out := &runtimetesting.ExternalComplex{}
125105
if err := scheme.Convert(&tc.input, out, nil); (tc.errFn == nil && err != nil) || (tc.errFn != nil && !tc.errFn(err)) {
126106
t.Errorf("%s: unexpected error: %v", k, err)
127107
continue

0 commit comments

Comments
 (0)