Skip to content

Commit 53cc85a

Browse files
committed
Expose k8s types that do not roundtrip and a helper to roundtrip without protobuf
1 parent db1990f commit 53cc85a

File tree

1 file changed

+32
-1
lines changed
  • staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip

1 file changed

+32
-1
lines changed

staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/roundtrip.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
"github.com/davecgh/go-spew/spew"
2828
"github.com/golang/protobuf/proto"
29-
"github.com/google/gofuzz"
29+
fuzz "github.com/google/gofuzz"
3030
flag "github.com/spf13/pflag"
3131

3232
apitesting "k8s.io/apimachinery/pkg/api/apitesting"
@@ -103,6 +103,23 @@ var globalNonRoundTrippableTypes = sets.NewString(
103103
"DeleteOptions",
104104
)
105105

106+
// GlobalNonRoundTrippableTypes returns the kinds that are effectively reserved across all GroupVersions.
107+
// They don't roundtrip and thus can be excluded in any custom/downstream roundtrip tests
108+
//
109+
// kinds := scheme.AllKnownTypes()
110+
// for gvk := range kinds {
111+
// if roundtrip.GlobalNonRoundTrippableTypes().Has(gvk.Kind) {
112+
// continue
113+
// }
114+
// t.Run(gvk.Group+"."+gvk.Version+"."+gvk.Kind, func(t *testing.T) {
115+
// // roundtrip test
116+
// })
117+
// }
118+
//
119+
func GlobalNonRoundTrippableTypes() sets.String {
120+
return sets.NewString(globalNonRoundTrippableTypes.List()...)
121+
}
122+
106123
// RoundTripTypesWithoutProtobuf applies the round-trip test to all round-trippable Kinds
107124
// in the scheme. It will skip all the GroupVersionKinds in the skip list.
108125
func RoundTripTypesWithoutProtobuf(t *testing.T, scheme *runtime.Scheme, codecFactory runtimeserializer.CodecFactory, fuzzer *fuzz.Fuzzer, nonRoundTrippableTypes map[schema.GroupVersionKind]bool) {
@@ -146,6 +163,20 @@ func RoundTripExternalTypes(t *testing.T, scheme *runtime.Scheme, codecFactory r
146163
}
147164
}
148165

166+
// RoundTripExternalTypesWithoutProtobuf applies the round-trip test to all external round-trippable Kinds
167+
// in the scheme. It will skip all the GroupVersionKinds in the nonRoundTripExternalTypes list.
168+
func RoundTripExternalTypesWithoutProtobuf(t *testing.T, scheme *runtime.Scheme, codecFactory runtimeserializer.CodecFactory, fuzzer *fuzz.Fuzzer, nonRoundTrippableTypes map[schema.GroupVersionKind]bool) {
169+
kinds := scheme.AllKnownTypes()
170+
for gvk := range kinds {
171+
if gvk.Version == runtime.APIVersionInternal || globalNonRoundTrippableTypes.Has(gvk.Kind) {
172+
continue
173+
}
174+
t.Run(gvk.Group+"."+gvk.Version+"."+gvk.Kind, func(t *testing.T) {
175+
roundTripSpecificKind(t, gvk, scheme, codecFactory, fuzzer, nonRoundTrippableTypes, true)
176+
})
177+
}
178+
}
179+
149180
func RoundTripSpecificKindWithoutProtobuf(t *testing.T, gvk schema.GroupVersionKind, scheme *runtime.Scheme, codecFactory runtimeserializer.CodecFactory, fuzzer *fuzz.Fuzzer, nonRoundTrippableTypes map[schema.GroupVersionKind]bool) {
150181
roundTripSpecificKind(t, gvk, scheme, codecFactory, fuzzer, nonRoundTrippableTypes, true)
151182
}

0 commit comments

Comments
 (0)