pkg/api: move *_test.go -> pkg/api/testing

This commit is contained in:
Dr. Stefan Schimanski 2017-10-09 15:53:03 +02:00
parent 73d1b38604
commit b926ca40de
15 changed files with 46 additions and 24 deletions

View File

@ -61,6 +61,7 @@ federation/test/e2e
federation/test/e2e/framework federation/test/e2e/framework
federation/test/e2e/upgrades federation/test/e2e/upgrades
federation/test/integration/framework federation/test/integration/framework
pkg/api
pkg/api/endpoints pkg/api/endpoints
pkg/api/helper pkg/api/helper
pkg/api/helper/qos pkg/api/helper/qos

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package v1_test package testing
import ( import (
"testing" "testing"

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package api_test package testing
import ( import (
"io/ioutil" "io/ioutil"
@ -27,11 +27,10 @@ import (
"k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/diff"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi" "k8s.io/kubernetes/pkg/api/testapi"
kapitesting "k8s.io/kubernetes/pkg/api/testing"
) )
func BenchmarkPodConversion(b *testing.B) { 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) items := make([]api.Pod, 4)
for i := range items { for i := range items {
apiObjectFuzzer.Fuzz(&items[i]) apiObjectFuzzer.Fuzz(&items[i])

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package api_test package testing
import ( import (
"bytes" "bytes"
@ -30,13 +30,12 @@ import (
"k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/diff"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi" "k8s.io/kubernetes/pkg/api/testapi"
kapitesting "k8s.io/kubernetes/pkg/api/testing"
) )
func TestDeepCopyApiObjects(t *testing.T) { func TestDeepCopyApiObjects(t *testing.T) {
for i := 0; i < *roundtrip.FuzzIters; i++ { for i := 0; i < *roundtrip.FuzzIters; i++ {
for _, version := range []schema.GroupVersion{testapi.Default.InternalGroupVersion(), api.Registry.GroupOrDie(api.GroupName).GroupVersion} { 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) { for kind := range api.Scheme.KnownTypes(version) {
doDeepCopyTest(t, version.WithKind(kind), f) 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) { func TestDeepCopySingleType(t *testing.T) {
for i := 0; i < *roundtrip.FuzzIters; i++ { for i := 0; i < *roundtrip.FuzzIters; i++ {
for _, version := range []schema.GroupVersion{testapi.Default.InternalGroupVersion(), api.Registry.GroupOrDie(api.GroupName).GroupVersion} { 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) doDeepCopyTest(t, version.WithKind("Pod"), f)
} }
} }

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package api_test package testing
import ( import (
"io/ioutil" "io/ioutil"

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package api_test package testing
import ( import (
"math/rand" "math/rand"

20
pkg/api/testing/doc.go Normal file
View File

@ -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

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package api_test package testing
import ( import (
"reflect" "reflect"

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package api_test package testing
import ( import (
"bytes" "bytes"
@ -34,7 +34,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/serializer/protobuf" "k8s.io/apimachinery/pkg/runtime/serializer/protobuf"
"k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/diff"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
kapitesting "k8s.io/kubernetes/pkg/api/testing"
_ "k8s.io/kubernetes/pkg/apis/extensions" _ "k8s.io/kubernetes/pkg/apis/extensions"
_ "k8s.io/kubernetes/pkg/apis/extensions/v1beta1" _ "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
) )
@ -98,7 +97,7 @@ func fieldsHaveProtobufTags(obj reflect.Type) error {
func TestProtobufRoundTrip(t *testing.T) { func TestProtobufRoundTrip(t *testing.T) {
obj := &v1.Pod{} 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. // InitContainers are turned into annotations by conversion.
obj.Spec.InitContainers = nil obj.Spec.InitContainers = nil
obj.Status.InitContainerStatuses = nil obj.Status.InitContainerStatuses = nil

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package api_test package testing
import ( import (
"bytes" "bytes"
@ -45,7 +45,6 @@ import (
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi" "k8s.io/kubernetes/pkg/api/testapi"
kapitesting "k8s.io/kubernetes/pkg/api/testing"
k8s_api_v1 "k8s.io/kubernetes/pkg/api/v1" k8s_api_v1 "k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/extensions"
k8s_v1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1" k8s_v1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
@ -54,7 +53,7 @@ import (
// fuzzInternalObject fuzzes an arbitrary runtime object using the appropriate // fuzzInternalObject fuzzes an arbitrary runtime object using the appropriate
// fuzzer registered with the apitesting package. // fuzzer registered with the apitesting package.
func fuzzInternalObject(t *testing.T, forVersion schema.GroupVersion, item runtime.Object, seed int64) runtime.Object { 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) j, err := meta.TypeAccessor(item)
if err != nil { if err != nil {
@ -144,7 +143,7 @@ func TestSpecificKind(t *testing.T) {
internalGVK := schema.GroupVersionKind{Group: "extensions", Version: runtime.APIVersionInternal, Kind: "DaemonSet"} internalGVK := schema.GroupVersionKind{Group: "extensions", Version: runtime.APIVersionInternal, Kind: "DaemonSet"}
seed := rand.Int63() 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) 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. // in all of the API groups registered for test in the testapi package.
func TestRoundTripTypes(t *testing.T) { func TestRoundTripTypes(t *testing.T) {
seed := rand.Int63() 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{ nonRoundTrippableTypes := map[schema.GroupVersionKind]bool{
{Group: "componentconfig", Version: runtime.APIVersionInternal, Kind: "KubeProxyConfiguration"}: true, {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 // TestObjectWatchFraming establishes that a watch event can be encoded and
// decoded correctly through each of the supported RFC2046 media types. // decoded correctly through each of the supported RFC2046 media types.
func TestObjectWatchFraming(t *testing.T) { 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{} secret := &api.Secret{}
f.Fuzz(secret) f.Fuzz(secret)
secret.Data["binary"] = []byte{0x00, 0x10, 0x30, 0x55, 0xff, 0x00} secret.Data["binary"] = []byte{0x00, 0x10, 0x30, 0x55, 0xff, 0x00}
@ -382,7 +381,7 @@ func TestObjectWatchFraming(t *testing.T) {
const benchmarkSeed = 100 const benchmarkSeed = 100
func benchmarkItems(b *testing.B) []v1.Pod { 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) items := make([]v1.Pod, 10)
for i := range items { for i := range items {
var pod api.Pod var pod api.Pod

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package api_test package testing
import ( import (
"math/rand" "math/rand"
@ -32,7 +32,6 @@ import (
"k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/json"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/testapi" "k8s.io/kubernetes/pkg/api/testapi"
kapitesting "k8s.io/kubernetes/pkg/api/testing"
) )
func doRoundTrip(t *testing.T, group testapi.TestGroup, kind string) { 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) t.Fatalf("Couldn't create internal object %v: %v", kind, err)
} }
seed := rand.Int63() 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 // We are explicitly overwriting custom fuzzing functions, to ensure
// that InitContainers and their statuses are not generated. This is // that InitContainers and their statuses are not generated. This is
// because in thise test we are simply doing json operations, in which // because in thise test we are simply doing json operations, in which

View File

@ -30,6 +30,9 @@ import (
"k8s.io/apimachinery/pkg/util/diff" "k8s.io/apimachinery/pkg/util/diff"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
k8s_api_v1 "k8s.io/kubernetes/pkg/api/v1" 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) { func TestPodLogOptions(t *testing.T) {

View File

@ -28,6 +28,9 @@ import (
"k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
k8s_api_v1 "k8s.io/kubernetes/pkg/api/v1" 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 { func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {