From b926ca40dec91d72c3a46902dc98bf404f002acb Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Mon, 9 Oct 2017 15:53:03 +0200 Subject: [PATCH] pkg/api: move *_test.go -> pkg/api/testing --- hack/.golint_failures | 1 + .../backward_compatibility_test.go | 2 +- pkg/api/{ => testing}/conversion_test.go | 5 ++--- pkg/api/{ => testing}/copy_test.go | 7 +++---- pkg/api/{ => testing}/deep_copy_test.go | 2 +- pkg/api/{ => testing}/defaulting_test.go | 2 +- pkg/api/testing/doc.go | 20 +++++++++++++++++++ pkg/api/{ => testing}/meta_test.go | 2 +- pkg/api/{ => testing}/node_example.json | 0 .../replication_controller_example.json | 0 .../{ => testing}/serialization_proto_test.go | 5 ++--- pkg/api/{ => testing}/serialization_test.go | 13 ++++++------ pkg/api/{ => testing}/unstructured_test.go | 5 ++--- pkg/api/v1/conversion_test.go | 3 +++ pkg/api/v1/defaults_test.go | 3 +++ 15 files changed, 46 insertions(+), 24 deletions(-) rename pkg/api/{v1 => testing}/backward_compatibility_test.go (99%) rename pkg/api/{ => testing}/conversion_test.go (95%) rename pkg/api/{ => testing}/copy_test.go (91%) rename pkg/api/{ => testing}/deep_copy_test.go (99%) rename pkg/api/{ => testing}/defaulting_test.go (99%) create mode 100644 pkg/api/testing/doc.go rename pkg/api/{ => testing}/meta_test.go (99%) rename pkg/api/{ => testing}/node_example.json (100%) rename pkg/api/{ => testing}/replication_controller_example.json (100%) rename pkg/api/{ => testing}/serialization_proto_test.go (97%) rename pkg/api/{ => testing}/serialization_test.go (97%) rename pkg/api/{ => testing}/unstructured_test.go (97%) diff --git a/hack/.golint_failures b/hack/.golint_failures index b4ab4b6a8e6..8ee21173e59 100644 --- a/hack/.golint_failures +++ b/hack/.golint_failures @@ -61,6 +61,7 @@ federation/test/e2e federation/test/e2e/framework federation/test/e2e/upgrades federation/test/integration/framework +pkg/api pkg/api/endpoints pkg/api/helper pkg/api/helper/qos diff --git a/pkg/api/v1/backward_compatibility_test.go b/pkg/api/testing/backward_compatibility_test.go similarity index 99% rename from pkg/api/v1/backward_compatibility_test.go rename to pkg/api/testing/backward_compatibility_test.go index 83c7107f960..82ac3ca81ae 100644 --- a/pkg/api/v1/backward_compatibility_test.go +++ b/pkg/api/testing/backward_compatibility_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1_test +package testing import ( "testing" diff --git a/pkg/api/conversion_test.go b/pkg/api/testing/conversion_test.go similarity index 95% rename from pkg/api/conversion_test.go rename to pkg/api/testing/conversion_test.go index b4c79696cd6..a594431ecad 100644 --- a/pkg/api/conversion_test.go +++ b/pkg/api/testing/conversion_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package api_test +package testing import ( "io/ioutil" @@ -27,11 +27,10 @@ import ( "k8s.io/apimachinery/pkg/util/diff" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/testapi" - kapitesting "k8s.io/kubernetes/pkg/api/testing" ) func BenchmarkPodConversion(b *testing.B) { - apiObjectFuzzer := fuzzer.FuzzerFor(kapitesting.FuzzerFuncs, rand.NewSource(benchmarkSeed), api.Codecs) + apiObjectFuzzer := fuzzer.FuzzerFor(FuzzerFuncs, rand.NewSource(benchmarkSeed), api.Codecs) items := make([]api.Pod, 4) for i := range items { apiObjectFuzzer.Fuzz(&items[i]) diff --git a/pkg/api/copy_test.go b/pkg/api/testing/copy_test.go similarity index 91% rename from pkg/api/copy_test.go rename to pkg/api/testing/copy_test.go index 1ca0df20cc8..e1002706dc1 100644 --- a/pkg/api/copy_test.go +++ b/pkg/api/testing/copy_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package api_test +package testing import ( "bytes" @@ -30,13 +30,12 @@ import ( "k8s.io/apimachinery/pkg/util/diff" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/testapi" - kapitesting "k8s.io/kubernetes/pkg/api/testing" ) func TestDeepCopyApiObjects(t *testing.T) { for i := 0; i < *roundtrip.FuzzIters; i++ { for _, version := range []schema.GroupVersion{testapi.Default.InternalGroupVersion(), api.Registry.GroupOrDie(api.GroupName).GroupVersion} { - f := fuzzer.FuzzerFor(kapitesting.FuzzerFuncs, rand.NewSource(rand.Int63()), api.Codecs) + f := fuzzer.FuzzerFor(FuzzerFuncs, rand.NewSource(rand.Int63()), api.Codecs) for kind := range api.Scheme.KnownTypes(version) { doDeepCopyTest(t, version.WithKind(kind), f) } @@ -80,7 +79,7 @@ func doDeepCopyTest(t *testing.T, kind schema.GroupVersionKind, f *fuzz.Fuzzer) func TestDeepCopySingleType(t *testing.T) { for i := 0; i < *roundtrip.FuzzIters; i++ { for _, version := range []schema.GroupVersion{testapi.Default.InternalGroupVersion(), api.Registry.GroupOrDie(api.GroupName).GroupVersion} { - f := fuzzer.FuzzerFor(kapitesting.FuzzerFuncs, rand.NewSource(rand.Int63()), api.Codecs) + f := fuzzer.FuzzerFor(FuzzerFuncs, rand.NewSource(rand.Int63()), api.Codecs) doDeepCopyTest(t, version.WithKind("Pod"), f) } } diff --git a/pkg/api/deep_copy_test.go b/pkg/api/testing/deep_copy_test.go similarity index 99% rename from pkg/api/deep_copy_test.go rename to pkg/api/testing/deep_copy_test.go index d88b6bb5ee7..a9580235e6e 100644 --- a/pkg/api/deep_copy_test.go +++ b/pkg/api/testing/deep_copy_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package api_test +package testing import ( "io/ioutil" diff --git a/pkg/api/defaulting_test.go b/pkg/api/testing/defaulting_test.go similarity index 99% rename from pkg/api/defaulting_test.go rename to pkg/api/testing/defaulting_test.go index e887eaa48d8..a54d49a21fc 100644 --- a/pkg/api/defaulting_test.go +++ b/pkg/api/testing/defaulting_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package api_test +package testing import ( "math/rand" diff --git a/pkg/api/testing/doc.go b/pkg/api/testing/doc.go new file mode 100644 index 00000000000..279404da564 --- /dev/null +++ b/pkg/api/testing/doc.go @@ -0,0 +1,20 @@ +/* +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. +*/ + +// Package testing contains +// - all generic API tests which depend on Kubernetes API types +// - all cross-Kubernetes-API tests. +package testing diff --git a/pkg/api/meta_test.go b/pkg/api/testing/meta_test.go similarity index 99% rename from pkg/api/meta_test.go rename to pkg/api/testing/meta_test.go index f97758188ca..32a6cc67f89 100644 --- a/pkg/api/meta_test.go +++ b/pkg/api/testing/meta_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package api_test +package testing import ( "reflect" diff --git a/pkg/api/node_example.json b/pkg/api/testing/node_example.json similarity index 100% rename from pkg/api/node_example.json rename to pkg/api/testing/node_example.json diff --git a/pkg/api/replication_controller_example.json b/pkg/api/testing/replication_controller_example.json similarity index 100% rename from pkg/api/replication_controller_example.json rename to pkg/api/testing/replication_controller_example.json diff --git a/pkg/api/serialization_proto_test.go b/pkg/api/testing/serialization_proto_test.go similarity index 97% rename from pkg/api/serialization_proto_test.go rename to pkg/api/testing/serialization_proto_test.go index b33d7eaeb5d..9e3b040958f 100644 --- a/pkg/api/serialization_proto_test.go +++ b/pkg/api/testing/serialization_proto_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package api_test +package testing import ( "bytes" @@ -34,7 +34,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/serializer/protobuf" "k8s.io/apimachinery/pkg/util/diff" "k8s.io/kubernetes/pkg/api" - kapitesting "k8s.io/kubernetes/pkg/api/testing" _ "k8s.io/kubernetes/pkg/apis/extensions" _ "k8s.io/kubernetes/pkg/apis/extensions/v1beta1" ) @@ -98,7 +97,7 @@ func fieldsHaveProtobufTags(obj reflect.Type) error { func TestProtobufRoundTrip(t *testing.T) { obj := &v1.Pod{} - fuzzer.FuzzerFor(kapitesting.FuzzerFuncs, rand.NewSource(benchmarkSeed), api.Codecs).Fuzz(obj) + fuzzer.FuzzerFor(FuzzerFuncs, rand.NewSource(benchmarkSeed), api.Codecs).Fuzz(obj) // InitContainers are turned into annotations by conversion. obj.Spec.InitContainers = nil obj.Status.InitContainerStatuses = nil diff --git a/pkg/api/serialization_test.go b/pkg/api/testing/serialization_test.go similarity index 97% rename from pkg/api/serialization_test.go rename to pkg/api/testing/serialization_test.go index 609805a8a74..ab139c88f72 100644 --- a/pkg/api/serialization_test.go +++ b/pkg/api/testing/serialization_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package api_test +package testing import ( "bytes" @@ -45,7 +45,6 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/testapi" - kapitesting "k8s.io/kubernetes/pkg/api/testing" k8s_api_v1 "k8s.io/kubernetes/pkg/api/v1" "k8s.io/kubernetes/pkg/apis/extensions" k8s_v1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1" @@ -54,7 +53,7 @@ import ( // fuzzInternalObject fuzzes an arbitrary runtime object using the appropriate // fuzzer registered with the apitesting package. func fuzzInternalObject(t *testing.T, forVersion schema.GroupVersion, item runtime.Object, seed int64) runtime.Object { - fuzzer.FuzzerFor(kapitesting.FuzzerFuncs, rand.NewSource(seed), api.Codecs).Fuzz(item) + fuzzer.FuzzerFor(FuzzerFuncs, rand.NewSource(seed), api.Codecs).Fuzz(item) j, err := meta.TypeAccessor(item) if err != nil { @@ -144,7 +143,7 @@ func TestSpecificKind(t *testing.T) { internalGVK := schema.GroupVersionKind{Group: "extensions", Version: runtime.APIVersionInternal, Kind: "DaemonSet"} seed := rand.Int63() - fuzzer := fuzzer.FuzzerFor(kapitesting.FuzzerFuncs, rand.NewSource(seed), api.Codecs) + fuzzer := fuzzer.FuzzerFor(FuzzerFuncs, rand.NewSource(seed), api.Codecs) roundtrip.RoundTripSpecificKind(t, internalGVK, api.Scheme, api.Codecs, fuzzer, nil) } @@ -205,7 +204,7 @@ func TestCommonKindsRegistered(t *testing.T) { // in all of the API groups registered for test in the testapi package. func TestRoundTripTypes(t *testing.T) { seed := rand.Int63() - fuzzer := fuzzer.FuzzerFor(kapitesting.FuzzerFuncs, rand.NewSource(seed), api.Codecs) + fuzzer := fuzzer.FuzzerFor(FuzzerFuncs, rand.NewSource(seed), api.Codecs) nonRoundTrippableTypes := map[schema.GroupVersionKind]bool{ {Group: "componentconfig", Version: runtime.APIVersionInternal, Kind: "KubeProxyConfiguration"}: true, @@ -300,7 +299,7 @@ func TestUnversionedTypes(t *testing.T) { // TestObjectWatchFraming establishes that a watch event can be encoded and // decoded correctly through each of the supported RFC2046 media types. func TestObjectWatchFraming(t *testing.T) { - f := fuzzer.FuzzerFor(kapitesting.FuzzerFuncs, rand.NewSource(benchmarkSeed), api.Codecs) + f := fuzzer.FuzzerFor(FuzzerFuncs, rand.NewSource(benchmarkSeed), api.Codecs) secret := &api.Secret{} f.Fuzz(secret) secret.Data["binary"] = []byte{0x00, 0x10, 0x30, 0x55, 0xff, 0x00} @@ -382,7 +381,7 @@ func TestObjectWatchFraming(t *testing.T) { const benchmarkSeed = 100 func benchmarkItems(b *testing.B) []v1.Pod { - apiObjectFuzzer := fuzzer.FuzzerFor(kapitesting.FuzzerFuncs, rand.NewSource(benchmarkSeed), api.Codecs) + apiObjectFuzzer := fuzzer.FuzzerFor(FuzzerFuncs, rand.NewSource(benchmarkSeed), api.Codecs) items := make([]v1.Pod, 10) for i := range items { var pod api.Pod diff --git a/pkg/api/unstructured_test.go b/pkg/api/testing/unstructured_test.go similarity index 97% rename from pkg/api/unstructured_test.go rename to pkg/api/testing/unstructured_test.go index 9616d822a7b..4b2f622885c 100644 --- a/pkg/api/unstructured_test.go +++ b/pkg/api/testing/unstructured_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package api_test +package testing import ( "math/rand" @@ -32,7 +32,6 @@ import ( "k8s.io/apimachinery/pkg/util/json" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/testapi" - kapitesting "k8s.io/kubernetes/pkg/api/testing" ) func doRoundTrip(t *testing.T, group testapi.TestGroup, kind string) { @@ -44,7 +43,7 @@ func doRoundTrip(t *testing.T, group testapi.TestGroup, kind string) { t.Fatalf("Couldn't create internal object %v: %v", kind, err) } seed := rand.Int63() - fuzzer.FuzzerFor(kapitesting.FuzzerFuncs, rand.NewSource(seed), api.Codecs). + fuzzer.FuzzerFor(FuzzerFuncs, rand.NewSource(seed), api.Codecs). // We are explicitly overwriting custom fuzzing functions, to ensure // that InitContainers and their statuses are not generated. This is // because in thise test we are simply doing json operations, in which diff --git a/pkg/api/v1/conversion_test.go b/pkg/api/v1/conversion_test.go index f9401a61c58..961701b1755 100644 --- a/pkg/api/v1/conversion_test.go +++ b/pkg/api/v1/conversion_test.go @@ -30,6 +30,9 @@ import ( "k8s.io/apimachinery/pkg/util/diff" "k8s.io/kubernetes/pkg/api" k8s_api_v1 "k8s.io/kubernetes/pkg/api/v1" + + // enforce that all types are installed + _ "k8s.io/kubernetes/pkg/api/testapi" ) func TestPodLogOptions(t *testing.T) { diff --git a/pkg/api/v1/defaults_test.go b/pkg/api/v1/defaults_test.go index 01fa05266e8..f5ad77dabac 100644 --- a/pkg/api/v1/defaults_test.go +++ b/pkg/api/v1/defaults_test.go @@ -28,6 +28,9 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/kubernetes/pkg/api" k8s_api_v1 "k8s.io/kubernetes/pkg/api/v1" + + // enforce that all types are installed + _ "k8s.io/kubernetes/pkg/api/testapi" ) func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {