Merge pull request #59592 from soltysh/roundtrip_tests

Automatic merge from submit-queue (batch tested with PRs 59592, 62308, 62523, 62635, 62243). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Roundtrip test helper for external types

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #54698

**Special notes for your reviewer**:
/assign @deads2k @sttts 
Since you've asked for it in the original issue. The FIXME I've pointed out to is worth addressing, but I'd prefer to do it afterwards. Do we want to implement appropriate test for all the api groups from `k8s.io/api` ?

**Release note**:
```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2018-04-19 14:50:13 -07:00 committed by GitHub
commit dffe94a0c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 370 additions and 30 deletions

View File

@ -11,36 +11,7 @@ filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//staging/src/k8s.io/api/admission/v1beta1:all-srcs",
"//staging/src/k8s.io/api/admissionregistration/v1alpha1:all-srcs",
"//staging/src/k8s.io/api/admissionregistration/v1beta1:all-srcs",
"//staging/src/k8s.io/api/apps/v1:all-srcs",
"//staging/src/k8s.io/api/apps/v1beta1:all-srcs",
"//staging/src/k8s.io/api/apps/v1beta2:all-srcs",
"//staging/src/k8s.io/api/authentication/v1:all-srcs",
"//staging/src/k8s.io/api/authentication/v1beta1:all-srcs",
"//staging/src/k8s.io/api/authorization/v1:all-srcs",
"//staging/src/k8s.io/api/authorization/v1beta1:all-srcs",
"//staging/src/k8s.io/api/autoscaling/v1:all-srcs",
"//staging/src/k8s.io/api/autoscaling/v2beta1:all-srcs",
"//staging/src/k8s.io/api/batch/v1:all-srcs",
"//staging/src/k8s.io/api/batch/v1beta1:all-srcs",
"//staging/src/k8s.io/api/batch/v2alpha1:all-srcs",
"//staging/src/k8s.io/api/certificates/v1beta1:all-srcs",
"//staging/src/k8s.io/api/core/v1:all-srcs",
"//staging/src/k8s.io/api/events/v1beta1:all-srcs",
"//staging/src/k8s.io/api/extensions/v1beta1:all-srcs",
"//staging/src/k8s.io/api/imagepolicy/v1alpha1:all-srcs",
"//staging/src/k8s.io/api/networking/v1:all-srcs",
"//staging/src/k8s.io/api/policy/v1beta1:all-srcs",
"//staging/src/k8s.io/api/rbac/v1:all-srcs",
"//staging/src/k8s.io/api/rbac/v1alpha1:all-srcs",
"//staging/src/k8s.io/api/rbac/v1beta1:all-srcs",
"//staging/src/k8s.io/api/scheduling/v1alpha1:all-srcs",
"//staging/src/k8s.io/api/settings/v1alpha1:all-srcs",
"//staging/src/k8s.io/api/storage/v1:all-srcs",
"//staging/src/k8s.io/api/storage/v1alpha1:all-srcs",
"//staging/src/k8s.io/api/storage/v1beta1:all-srcs",
"//staging/src/k8s.io/api:all-srcs",
"//staging/src/k8s.io/apiextensions-apiserver:all-srcs",
"//staging/src/k8s.io/apimachinery/pkg/api/equality:all-srcs",
"//staging/src/k8s.io/apimachinery/pkg/api/errors:all-srcs",

View File

@ -0,0 +1,91 @@
load("@io_bazel_rules_go//go:def.bzl", "go_test")
go_test(
name = "go_default_test",
srcs = ["roundtrip_test.go"],
deps = [
"//vendor/k8s.io/api/admission/v1beta1:go_default_library",
"//vendor/k8s.io/api/admissionregistration/v1alpha1:go_default_library",
"//vendor/k8s.io/api/admissionregistration/v1beta1:go_default_library",
"//vendor/k8s.io/api/apps/v1:go_default_library",
"//vendor/k8s.io/api/apps/v1beta1:go_default_library",
"//vendor/k8s.io/api/apps/v1beta2:go_default_library",
"//vendor/k8s.io/api/authentication/v1:go_default_library",
"//vendor/k8s.io/api/authentication/v1beta1:go_default_library",
"//vendor/k8s.io/api/authorization/v1:go_default_library",
"//vendor/k8s.io/api/authorization/v1beta1:go_default_library",
"//vendor/k8s.io/api/autoscaling/v1:go_default_library",
"//vendor/k8s.io/api/autoscaling/v2beta1:go_default_library",
"//vendor/k8s.io/api/batch/v1:go_default_library",
"//vendor/k8s.io/api/batch/v1beta1:go_default_library",
"//vendor/k8s.io/api/batch/v2alpha1:go_default_library",
"//vendor/k8s.io/api/certificates/v1beta1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/events/v1beta1:go_default_library",
"//vendor/k8s.io/api/extensions/v1beta1:go_default_library",
"//vendor/k8s.io/api/imagepolicy/v1alpha1:go_default_library",
"//vendor/k8s.io/api/networking/v1:go_default_library",
"//vendor/k8s.io/api/policy/v1beta1:go_default_library",
"//vendor/k8s.io/api/rbac/v1:go_default_library",
"//vendor/k8s.io/api/rbac/v1alpha1:go_default_library",
"//vendor/k8s.io/api/rbac/v1beta1:go_default_library",
"//vendor/k8s.io/api/scheduling/v1alpha1:go_default_library",
"//vendor/k8s.io/api/settings/v1alpha1:go_default_library",
"//vendor/k8s.io/api/storage/v1:go_default_library",
"//vendor/k8s.io/api/storage/v1alpha1:go_default_library",
"//vendor/k8s.io/api/storage/v1beta1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/testing/fuzzer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/testing/roundtrip:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/fuzzer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//staging/src/k8s.io/api/admission/v1beta1:all-srcs",
"//staging/src/k8s.io/api/admissionregistration/v1alpha1:all-srcs",
"//staging/src/k8s.io/api/admissionregistration/v1beta1:all-srcs",
"//staging/src/k8s.io/api/apps/v1:all-srcs",
"//staging/src/k8s.io/api/apps/v1beta1:all-srcs",
"//staging/src/k8s.io/api/apps/v1beta2:all-srcs",
"//staging/src/k8s.io/api/authentication/v1:all-srcs",
"//staging/src/k8s.io/api/authentication/v1beta1:all-srcs",
"//staging/src/k8s.io/api/authorization/v1:all-srcs",
"//staging/src/k8s.io/api/authorization/v1beta1:all-srcs",
"//staging/src/k8s.io/api/autoscaling/v1:all-srcs",
"//staging/src/k8s.io/api/autoscaling/v2beta1:all-srcs",
"//staging/src/k8s.io/api/batch/v1:all-srcs",
"//staging/src/k8s.io/api/batch/v1beta1:all-srcs",
"//staging/src/k8s.io/api/batch/v2alpha1:all-srcs",
"//staging/src/k8s.io/api/certificates/v1beta1:all-srcs",
"//staging/src/k8s.io/api/core/v1:all-srcs",
"//staging/src/k8s.io/api/events/v1beta1:all-srcs",
"//staging/src/k8s.io/api/extensions/v1beta1:all-srcs",
"//staging/src/k8s.io/api/imagepolicy/v1alpha1:all-srcs",
"//staging/src/k8s.io/api/networking/v1:all-srcs",
"//staging/src/k8s.io/api/policy/v1beta1:all-srcs",
"//staging/src/k8s.io/api/rbac/v1:all-srcs",
"//staging/src/k8s.io/api/rbac/v1alpha1:all-srcs",
"//staging/src/k8s.io/api/rbac/v1beta1:all-srcs",
"//staging/src/k8s.io/api/scheduling/v1alpha1:all-srcs",
"//staging/src/k8s.io/api/settings/v1alpha1:all-srcs",
"//staging/src/k8s.io/api/storage/v1:all-srcs",
"//staging/src/k8s.io/api/storage/v1alpha1:all-srcs",
"//staging/src/k8s.io/api/storage/v1beta1:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -6,6 +6,14 @@
"./..."
],
"Deps": [
{
"ImportPath": "github.com/davecgh/go-spew/spew",
"Rev": "782f4967f2dc4564575ca782fe2d04090b5faca8"
},
{
"ImportPath": "github.com/ghodss/yaml",
"Rev": "73d445a93680fa1a78ae23a5839bad48f32ba1ee"
},
{
"ImportPath": "github.com/gogo/protobuf/proto",
"Rev": "c0656edd0d9eab7c66d1eb0c568f9039345796f7"
@ -18,10 +26,18 @@
"ImportPath": "github.com/golang/glog",
"Rev": "44145f04b68cf362d9c4df2182967c2275eaefed"
},
{
"ImportPath": "github.com/golang/protobuf/proto",
"Rev": "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
},
{
"ImportPath": "github.com/google/gofuzz",
"Rev": "44d81051d367757e1c7c6a5a86423ece9afcf63c"
},
{
"ImportPath": "github.com/json-iterator/go",
"Rev": "13f86432b882000a51c6e610c620974462691a97"
},
{
"ImportPath": "github.com/spf13/pflag",
"Rev": "583c0c0531f06d5278b7d917446061adc344b5cd"
@ -62,10 +78,58 @@
"ImportPath": "gopkg.in/inf.v0",
"Rev": "3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4"
},
{
"ImportPath": "gopkg.in/yaml.v2",
"Rev": "670d4cfef0544295bc27a114dbac37980d83185a"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/equality",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/meta",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/resource",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/testing",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/testing/fuzzer",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apimachinery",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apimachinery/announced",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apimachinery/registered",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/fuzzer",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1beta1",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/conversion",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@ -90,6 +154,26 @@
"ImportPath": "k8s.io/apimachinery/pkg/runtime/schema",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/selection",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@ -98,10 +182,18 @@
"ImportPath": "k8s.io/apimachinery/pkg/types",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/diff",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/errors",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/framer",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/intstr",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@ -134,6 +226,10 @@
"ImportPath": "k8s.io/apimachinery/pkg/util/wait",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/yaml",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/watch",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@ -146,6 +242,18 @@
"ImportPath": "k8s.io/apimachinery/pkg/api/resource",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/testing/fuzzer",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/testing/roundtrip",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/fuzzer",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@ -158,6 +266,10 @@
"ImportPath": "k8s.io/apimachinery/pkg/runtime/schema",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/types",
"Rev": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

View File

@ -0,0 +1,148 @@
/*
Copyright 2018 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 (
"math/rand"
"testing"
admissionv1beta1 "k8s.io/api/admission/v1beta1"
admissionregv1alpha1 "k8s.io/api/admissionregistration/v1alpha1"
admissionregv1beta1 "k8s.io/api/admissionregistration/v1beta1"
appsv1 "k8s.io/api/apps/v1"
appsv1beta1 "k8s.io/api/apps/v1beta1"
appsv1beta2 "k8s.io/api/apps/v1beta2"
authenticationv1 "k8s.io/api/authentication/v1"
authenticationv1beta1 "k8s.io/api/authentication/v1beta1"
authorizationv1 "k8s.io/api/authorization/v1"
authorizationv1beta1 "k8s.io/api/authorization/v1beta1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
autoscalingv2beta1 "k8s.io/api/autoscaling/v2beta1"
batchv1 "k8s.io/api/batch/v1"
batchv1beta1 "k8s.io/api/batch/v1beta1"
batchv2alpha1 "k8s.io/api/batch/v2alpha1"
certificatesv1beta1 "k8s.io/api/certificates/v1beta1"
corev1 "k8s.io/api/core/v1"
eventsv1beta1 "k8s.io/api/events/v1beta1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
imagepolicyv1alpha1 "k8s.io/api/imagepolicy/v1alpha1"
networkingv1 "k8s.io/api/networking/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1"
rbacv1 "k8s.io/api/rbac/v1"
rbacv1alpha1 "k8s.io/api/rbac/v1alpha1"
rbacv1beta1 "k8s.io/api/rbac/v1beta1"
schedulingv1alpha1 "k8s.io/api/scheduling/v1alpha1"
settingsv1alpha1 "k8s.io/api/settings/v1alpha1"
storagev1 "k8s.io/api/storage/v1"
storagev1alpha1 "k8s.io/api/storage/v1alpha1"
storagev1beta1 "k8s.io/api/storage/v1beta1"
"k8s.io/apimachinery/pkg/api/testing/fuzzer"
"k8s.io/apimachinery/pkg/api/testing/roundtrip"
genericfuzzer "k8s.io/apimachinery/pkg/apis/meta/fuzzer"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
)
var groups = []runtime.SchemeBuilder{
admissionv1beta1.SchemeBuilder,
admissionregv1alpha1.SchemeBuilder,
admissionregv1beta1.SchemeBuilder,
appsv1beta1.SchemeBuilder,
appsv1beta2.SchemeBuilder,
appsv1.SchemeBuilder,
authenticationv1beta1.SchemeBuilder,
authenticationv1.SchemeBuilder,
authorizationv1beta1.SchemeBuilder,
authorizationv1.SchemeBuilder,
autoscalingv1.SchemeBuilder,
autoscalingv2beta1.SchemeBuilder,
batchv2alpha1.SchemeBuilder,
batchv1beta1.SchemeBuilder,
batchv1.SchemeBuilder,
certificatesv1beta1.SchemeBuilder,
corev1.SchemeBuilder,
eventsv1beta1.SchemeBuilder,
extensionsv1beta1.SchemeBuilder,
imagepolicyv1alpha1.SchemeBuilder,
networkingv1.SchemeBuilder,
policyv1beta1.SchemeBuilder,
rbacv1alpha1.SchemeBuilder,
rbacv1beta1.SchemeBuilder,
rbacv1.SchemeBuilder,
schedulingv1alpha1.SchemeBuilder,
settingsv1alpha1.SchemeBuilder,
storagev1alpha1.SchemeBuilder,
storagev1beta1.SchemeBuilder,
storagev1.SchemeBuilder,
}
func TestRoundTripExternalTypes(t *testing.T) {
for _, builder := range groups {
scheme := runtime.NewScheme()
codecs := serializer.NewCodecFactory(scheme)
builder.AddToScheme(scheme)
seed := rand.Int63()
// I'm only using the generic fuzzer funcs, but at some point in time we might need to
// switch to specialized. For now we're happy with the current serialization test.
fuzzer := fuzzer.FuzzerFor(genericfuzzer.Funcs, rand.NewSource(seed), codecs)
roundtrip.RoundTripExternalTypes(t, scheme, codecs, fuzzer, nil)
}
}
func TestFailRoundTrip(t *testing.T) {
scheme := runtime.NewScheme()
codecs := serializer.NewCodecFactory(scheme)
groupVersion := schema.GroupVersion{Group: "broken", Version: "v1"}
builder := runtime.NewSchemeBuilder(func(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(groupVersion, &BrokenType{})
metav1.AddToGroupVersion(scheme, groupVersion)
return nil
})
builder.AddToScheme(scheme)
seed := rand.Int63()
fuzzer := fuzzer.FuzzerFor(genericfuzzer.Funcs, rand.NewSource(seed), codecs)
tmpT := new(testing.T)
roundtrip.RoundTripExternalTypes(tmpT, scheme, codecs, fuzzer, nil)
// It's very hacky way of making sure the DeepCopy is actually invoked inside RoundTripExternalTypes
// used in the other test. If for some reason this tests starts passing we need to fail b/c we're not testing
// the DeepCopy in the other method which we care so much about.
if !tmpT.Failed() {
t.Log("RoundTrip should've failed on DeepCopy but it did not!")
t.FailNow()
}
}
type BrokenType struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Field1 string `json:"field1,omitempty"`
Field2 string `json:"field2,omitempty"`
}
func (in *BrokenType) DeepCopy() *BrokenType {
return new(BrokenType)
}
func (in *BrokenType) DeepCopyObject() runtime.Object {
return in.DeepCopy()
}

View File

@ -138,6 +138,24 @@ func roundTripTypes(t *testing.T, scheme *runtime.Scheme, codecFactory runtimese
}
}
// RoundTripExternalTypes applies the round-trip test to all external round-trippable Kinds
// in the scheme. It will skip all the GroupVersionKinds in the nonRoundTripExternalTypes list .
func RoundTripExternalTypes(t *testing.T, scheme *runtime.Scheme, codecFactory runtimeserializer.CodecFactory, fuzzer *fuzz.Fuzzer, nonRoundTrippableTypes map[schema.GroupVersionKind]bool) {
kinds := scheme.AllKnownTypes()
for gvk := range kinds {
if gvk.Version == runtime.APIVersionInternal || globalNonRoundTrippableTypes.Has(gvk.Kind) {
continue
}
// FIXME: this is explicitly testing w/o protobuf which was failing if enabled
// the reason for that is that protobuf is not setting Kind and APIVersion fields
// during obj2 decode, the same then applies to DecodeInto obj3. My guess is we
// should be setting these two fields accordingly when protobuf is passed as codec
// to roundTrip method.
roundTripSpecificKind(t, gvk, scheme, codecFactory, fuzzer, nonRoundTrippableTypes, true)
}
}
func RoundTripSpecificKindWithoutProtobuf(t *testing.T, gvk schema.GroupVersionKind, scheme *runtime.Scheme, codecFactory runtimeserializer.CodecFactory, fuzzer *fuzz.Fuzzer, nonRoundTrippableTypes map[schema.GroupVersionKind]bool) {
roundTripSpecificKind(t, gvk, scheme, codecFactory, fuzzer, nonRoundTrippableTypes, true)
}