Use randfill, do API renames
Kubernetes-commit: e54719bb6674fac228671e0786d19c2cf27b08a3
This commit is contained in:
parent
c2e94ca503
commit
9641d30242
|
@ -22,16 +22,16 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
fuzz "github.com/google/gofuzz"
|
||||
v1 "k8s.io/api/admissionregistration/v1"
|
||||
"sigs.k8s.io/randfill"
|
||||
)
|
||||
|
||||
func TestMutatingWebhookAccessor(t *testing.T) {
|
||||
f := fuzz.New()
|
||||
f := randfill.New()
|
||||
for i := 0; i < 100; i++ {
|
||||
t.Run(fmt.Sprintf("Run %d/100", i), func(t *testing.T) {
|
||||
orig := &v1.MutatingWebhook{}
|
||||
f.Fuzz(orig)
|
||||
f.Fill(orig)
|
||||
|
||||
// zero out any accessor type specific fields not included in the accessor
|
||||
orig.ReinvocationPolicy = nil
|
||||
|
@ -72,11 +72,11 @@ func TestMutatingWebhookAccessor(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestValidatingWebhookAccessor(t *testing.T) {
|
||||
f := fuzz.New()
|
||||
f := randfill.New()
|
||||
for i := 0; i < 100; i++ {
|
||||
t.Run(fmt.Sprintf("Run %d/100", i), func(t *testing.T) {
|
||||
orig := &v1.ValidatingWebhook{}
|
||||
f.Fuzz(orig)
|
||||
f.Fill(orig)
|
||||
uid := fmt.Sprintf("test.configuration.admission/%s/0", orig.Name)
|
||||
accessor := NewValidatingWebhookAccessor(uid, "test.configuration.admission", orig)
|
||||
if uid != accessor.GetUID() {
|
||||
|
|
|
@ -29,8 +29,8 @@ import (
|
|||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
fuzz "github.com/google/gofuzz"
|
||||
"github.com/stretchr/testify/require"
|
||||
"sigs.k8s.io/randfill"
|
||||
)
|
||||
|
||||
func TestConversionRoundTrip(t *testing.T) {
|
||||
|
@ -42,12 +42,12 @@ func TestConversionRoundTrip(t *testing.T) {
|
|||
err = v2scheme.RegisterConversions(scheme)
|
||||
require.NoError(t, err)
|
||||
|
||||
fuzzer := fuzz.NewWithSeed(2374375)
|
||||
fuzzer := randfill.NewWithSeed(2374375)
|
||||
|
||||
// v2 -> v2beta1 -> v2
|
||||
for i := 0; i < 100; i++ {
|
||||
expected := &v2.APIGroupDiscoveryList{}
|
||||
fuzzer.Fuzz(expected)
|
||||
fuzzer.Fill(expected)
|
||||
expected.TypeMeta = metav1.TypeMeta{
|
||||
Kind: "APIGroupDiscoveryList",
|
||||
APIVersion: "apidiscovery.k8s.io/v2",
|
||||
|
@ -68,7 +68,7 @@ func TestConversionRoundTrip(t *testing.T) {
|
|||
// v2beta1 -> v2 -> v2beta1
|
||||
for i := 0; i < 100; i++ {
|
||||
expected := &v2beta1.APIGroupDiscoveryList{}
|
||||
fuzzer.Fuzz(expected)
|
||||
fuzzer.Fill(expected)
|
||||
expected.TypeMeta = metav1.TypeMeta{
|
||||
Kind: "APIGroupDiscoveryList",
|
||||
APIVersion: "apidiscovery.k8s.io/v2beta1",
|
||||
|
|
|
@ -19,7 +19,7 @@ package fuzzer
|
|||
import (
|
||||
"strings"
|
||||
|
||||
fuzz "github.com/google/gofuzz"
|
||||
"sigs.k8s.io/randfill"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
|
@ -29,9 +29,9 @@ import (
|
|||
// Funcs returns the fuzzer functions for the audit api group.
|
||||
func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
|
||||
return []interface{}{
|
||||
func(e *audit.Event, c fuzz.Continue) {
|
||||
c.FuzzNoCustom(e)
|
||||
switch c.RandBool() {
|
||||
func(e *audit.Event, c randfill.Continue) {
|
||||
c.FillNoCustom(e)
|
||||
switch c.Bool() {
|
||||
case true:
|
||||
e.RequestObject = nil
|
||||
case false:
|
||||
|
@ -41,7 +41,7 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
|
|||
ContentType: runtime.ContentTypeJSON,
|
||||
}
|
||||
}
|
||||
switch c.RandBool() {
|
||||
switch c.Bool() {
|
||||
case true:
|
||||
e.ResponseObject = nil
|
||||
case false:
|
||||
|
@ -52,8 +52,8 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
|
|||
}
|
||||
}
|
||||
},
|
||||
func(o *audit.ObjectReference, c fuzz.Continue) {
|
||||
c.FuzzNoCustom(o)
|
||||
func(o *audit.ObjectReference, c randfill.Continue) {
|
||||
c.FillNoCustom(o)
|
||||
switch c.Intn(3) {
|
||||
case 0:
|
||||
// core api group
|
||||
|
|
|
@ -19,7 +19,7 @@ package fuzzer
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/gofuzz"
|
||||
"sigs.k8s.io/randfill"
|
||||
|
||||
apitesting "k8s.io/apimachinery/pkg/api/apitesting"
|
||||
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
|
||||
|
@ -33,9 +33,9 @@ import (
|
|||
// values in a Kubernetes context.
|
||||
func overrideMetaFuncs(codecs runtimeserializer.CodecFactory) []interface{} {
|
||||
return []interface{}{
|
||||
func(j *runtime.Object, c fuzz.Continue) {
|
||||
func(j *runtime.Object, c randfill.Continue) {
|
||||
// TODO: uncomment when round trip starts from a versioned object
|
||||
if true { //c.RandBool() {
|
||||
if true { // c.Bool() {
|
||||
*j = &runtime.Unknown{
|
||||
// We do not set TypeMeta here because it is not carried through a round trip
|
||||
Raw: []byte(`{"apiVersion":"unknown.group/unknown","kind":"Something","someKey":"someValue"}`),
|
||||
|
@ -44,15 +44,15 @@ func overrideMetaFuncs(codecs runtimeserializer.CodecFactory) []interface{} {
|
|||
} else {
|
||||
types := []runtime.Object{&example.Pod{}}
|
||||
t := types[c.Rand.Intn(len(types))]
|
||||
c.Fuzz(t)
|
||||
c.Fill(t)
|
||||
*j = t
|
||||
}
|
||||
},
|
||||
func(r *runtime.RawExtension, c fuzz.Continue) {
|
||||
func(r *runtime.RawExtension, c randfill.Continue) {
|
||||
// Pick an arbitrary type and fuzz it
|
||||
types := []runtime.Object{&example.Pod{}}
|
||||
obj := types[c.Rand.Intn(len(types))]
|
||||
c.Fuzz(obj)
|
||||
c.Fill(obj)
|
||||
|
||||
// Convert the object to raw bytes
|
||||
bytes, err := runtime.Encode(apitesting.TestCodec(codecs, examplev1.SchemeGroupVersion), obj)
|
||||
|
@ -68,11 +68,11 @@ func overrideMetaFuncs(codecs runtimeserializer.CodecFactory) []interface{} {
|
|||
|
||||
func exampleFuncs(codecs runtimeserializer.CodecFactory) []interface{} {
|
||||
return []interface{}{
|
||||
func(s *example.PodSpec, c fuzz.Continue) {
|
||||
c.FuzzNoCustom(s)
|
||||
func(s *example.PodSpec, c randfill.Continue) {
|
||||
c.FillNoCustom(s)
|
||||
// has a default value
|
||||
ttl := int64(30)
|
||||
if c.RandBool() {
|
||||
if c.Bool() {
|
||||
ttl = int64(c.Uint32())
|
||||
}
|
||||
s.TerminationGracePeriodSeconds = &ttl
|
||||
|
@ -81,11 +81,11 @@ func exampleFuncs(codecs runtimeserializer.CodecFactory) []interface{} {
|
|||
s.SchedulerName = "default-scheduler"
|
||||
}
|
||||
},
|
||||
func(j *example.PodPhase, c fuzz.Continue) {
|
||||
func(j *example.PodPhase, c randfill.Continue) {
|
||||
statuses := []example.PodPhase{"Pending", "Running", "Succeeded", "Failed", "Unknown"}
|
||||
*j = statuses[c.Rand.Intn(len(statuses))]
|
||||
},
|
||||
func(rp *example.RestartPolicy, c fuzz.Continue) {
|
||||
func(rp *example.RestartPolicy, c randfill.Continue) {
|
||||
policies := []example.RestartPolicy{"Always", "Never", "OnFailure"}
|
||||
*rp = policies[c.Rand.Intn(len(policies))]
|
||||
},
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
fuzz "github.com/google/gofuzz"
|
||||
"sigs.k8s.io/randfill"
|
||||
)
|
||||
|
||||
// TestEscaping tests that property names are escaped as expected.
|
||||
|
@ -143,10 +143,10 @@ func TestUnescapeMalformed(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestEscapingFuzz(t *testing.T) {
|
||||
fuzzer := fuzz.New()
|
||||
fuzzer := randfill.New()
|
||||
for i := 0; i < 1000; i++ {
|
||||
var unescaped string
|
||||
fuzzer.Fuzz(&unescaped)
|
||||
fuzzer.Fill(&unescaped)
|
||||
t.Run(fmt.Sprintf("%d - '%s'", i, unescaped), func(t *testing.T) {
|
||||
if len(unescaped) == 0 {
|
||||
return
|
||||
|
|
|
@ -4463,7 +4463,7 @@ func benchmarkItems(b *testing.B) []example.Pod {
|
|||
clientapiObjectFuzzer := fuzzer.FuzzerFor(examplefuzzer.Funcs, rand.NewSource(benchmarkSeed), codecs)
|
||||
items := make([]example.Pod, 3)
|
||||
for i := range items {
|
||||
clientapiObjectFuzzer.Fuzz(&items[i])
|
||||
clientapiObjectFuzzer.Fill(&items[i])
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ import (
|
|||
"sync"
|
||||
"testing"
|
||||
|
||||
fuzz "github.com/google/gofuzz"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"sigs.k8s.io/randfill"
|
||||
|
||||
apidiscoveryv2 "k8s.io/api/apidiscovery/v2"
|
||||
apidiscoveryv2beta1 "k8s.io/api/apidiscovery/v2beta1"
|
||||
|
@ -59,16 +59,16 @@ func init() {
|
|||
}
|
||||
|
||||
func fuzzAPIGroups(atLeastNumGroups, maxNumGroups int, seed int64) apidiscoveryv2.APIGroupDiscoveryList {
|
||||
fuzzer := fuzz.NewWithSeed(seed)
|
||||
fuzzer := randfill.NewWithSeed(seed)
|
||||
fuzzer.NumElements(atLeastNumGroups, maxNumGroups)
|
||||
fuzzer.NilChance(0)
|
||||
fuzzer.Funcs(func(o *apidiscoveryv2.APIGroupDiscovery, c fuzz.Continue) {
|
||||
c.FuzzNoCustom(o)
|
||||
fuzzer.Funcs(func(o *apidiscoveryv2.APIGroupDiscovery, c randfill.Continue) {
|
||||
c.FillNoCustom(o)
|
||||
|
||||
// The ResourceManager will just not serve the group if its versions
|
||||
// list is empty
|
||||
atLeastOne := apidiscoveryv2.APIVersionDiscovery{}
|
||||
c.Fuzz(&atLeastOne)
|
||||
c.Fill(&atLeastOne)
|
||||
o.Versions = append(o.Versions, atLeastOne)
|
||||
sort.Slice(o.Versions[:], func(i, j int) bool {
|
||||
return version.CompareKubeAwareVersionStrings(o.Versions[i].Version, o.Versions[j].Version) > 0
|
||||
|
@ -76,14 +76,14 @@ func fuzzAPIGroups(atLeastNumGroups, maxNumGroups int, seed int64) apidiscoveryv
|
|||
|
||||
o.TypeMeta = metav1.TypeMeta{}
|
||||
var name string
|
||||
c.Fuzz(&name)
|
||||
c.Fill(&name)
|
||||
o.ObjectMeta = metav1.ObjectMeta{
|
||||
Name: name,
|
||||
}
|
||||
})
|
||||
|
||||
var apis []apidiscoveryv2.APIGroupDiscovery
|
||||
fuzzer.Fuzz(&apis)
|
||||
fuzzer.Fill(&apis)
|
||||
sort.Slice(apis[:], func(i, j int) bool {
|
||||
return apis[i].Name < apis[j].Name
|
||||
})
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
fuzz "github.com/google/gofuzz"
|
||||
jsonpatch "gopkg.in/evanphx/json-patch.v4"
|
||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
|
@ -53,6 +52,7 @@ import (
|
|||
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/component-base/metrics/legacyregistry"
|
||||
"k8s.io/component-base/metrics/testutil"
|
||||
"sigs.k8s.io/randfill"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -991,11 +991,11 @@ func (alwaysErrorTyper) Recognizes(gvk schema.GroupVersionKind) bool {
|
|||
}
|
||||
|
||||
func TestUpdateToCreateOptions(t *testing.T) {
|
||||
f := fuzz.New()
|
||||
f := randfill.New()
|
||||
for i := 0; i < 100; i++ {
|
||||
t.Run(fmt.Sprintf("Run %d/100", i), func(t *testing.T) {
|
||||
update := &metav1.UpdateOptions{}
|
||||
f.Fuzz(update)
|
||||
f.Fill(update)
|
||||
create := updateToCreateOptions(update)
|
||||
|
||||
b, err := json.Marshal(create)
|
||||
|
@ -1038,13 +1038,13 @@ func TestPatchToUpdateOptions(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
f := fuzz.New()
|
||||
f := randfill.New()
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
for i := 0; i < 100; i++ {
|
||||
t.Run(fmt.Sprintf("Run %d/100", i), func(t *testing.T) {
|
||||
patch := &metav1.PatchOptions{}
|
||||
f.Fuzz(patch)
|
||||
f.Fill(patch)
|
||||
converted := test.converterFn(patch)
|
||||
|
||||
b, err := json.Marshal(converted)
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
fuzz "github.com/google/gofuzz"
|
||||
"sigs.k8s.io/randfill"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/apitesting"
|
||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||
|
@ -480,13 +480,13 @@ func TestStoreCreateWithRetryNameGenerateFeatureDisabled(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNewCreateOptionsFromUpdateOptions(t *testing.T) {
|
||||
f := fuzz.New().NilChance(0.0).NumElements(1, 1)
|
||||
f := randfill.New().NilChance(0.0).NumElements(1, 1)
|
||||
|
||||
// The goal here is to trigger when any changes are made to either
|
||||
// CreateOptions or UpdateOptions types, so we can update the converter.
|
||||
for i := 0; i < 20; i++ {
|
||||
in := &metav1.UpdateOptions{}
|
||||
f.Fuzz(in)
|
||||
f.Fill(in)
|
||||
in.TypeMeta.SetGroupVersionKind(metav1.SchemeGroupVersion.WithKind("CreateOptions"))
|
||||
|
||||
out := newCreateOptionsFromUpdateOptions(in)
|
||||
|
@ -532,13 +532,13 @@ func TestNewCreateOptionsFromUpdateOptions(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNewDeleteOptionsFromUpdateOptions(t *testing.T) {
|
||||
f := fuzz.New().NilChance(0.0).NumElements(1, 1)
|
||||
f := randfill.New().NilChance(0.0).NumElements(1, 1)
|
||||
|
||||
// The goal here is to trigger when any changes are made to either
|
||||
// DeleteOptions or UpdateOptions types, so we can update the converter.
|
||||
for i := 0; i < 20; i++ {
|
||||
in := &metav1.UpdateOptions{}
|
||||
f.Fuzz(in)
|
||||
f.Fill(in)
|
||||
in.TypeMeta.SetGroupVersionKind(metav1.SchemeGroupVersion.WithKind("DeleteOptions"))
|
||||
|
||||
out := newDeleteOptionsFromUpdateOptions(in)
|
||||
|
|
|
@ -24,22 +24,22 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
fuzz "github.com/google/gofuzz"
|
||||
"sigs.k8s.io/randfill"
|
||||
|
||||
authenticationv1 "k8s.io/api/authentication/v1"
|
||||
authenticationv1beta1 "k8s.io/api/authentication/v1beta1"
|
||||
)
|
||||
|
||||
func TestRoundTrip(t *testing.T) {
|
||||
f := fuzz.New()
|
||||
f := randfill.New()
|
||||
seed := time.Now().UnixNano()
|
||||
t.Logf("seed = %v", seed)
|
||||
f.RandSource(rand.New(rand.NewSource(seed)))
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
original := &authenticationv1.TokenReview{}
|
||||
f.Fuzz(&original.Spec)
|
||||
f.Fuzz(&original.Status)
|
||||
f.Fill(&original.Spec)
|
||||
f.Fill(&original.Status)
|
||||
converted := &authenticationv1beta1.TokenReview{
|
||||
Spec: v1SpecToV1beta1Spec(&original.Spec),
|
||||
Status: v1StatusToV1beta1Status(original.Status),
|
||||
|
|
|
@ -24,22 +24,22 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
fuzz "github.com/google/gofuzz"
|
||||
"sigs.k8s.io/randfill"
|
||||
|
||||
authorizationv1 "k8s.io/api/authorization/v1"
|
||||
authorizationv1beta1 "k8s.io/api/authorization/v1beta1"
|
||||
)
|
||||
|
||||
func TestRoundTrip(t *testing.T) {
|
||||
f := fuzz.New()
|
||||
f := randfill.New()
|
||||
seed := time.Now().UnixNano()
|
||||
t.Logf("seed = %v", seed)
|
||||
f.RandSource(rand.New(rand.NewSource(seed)))
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
original := &authorizationv1.SubjectAccessReview{}
|
||||
f.Fuzz(&original.Spec)
|
||||
f.Fuzz(&original.Status)
|
||||
f.Fill(&original.Spec)
|
||||
f.Fill(&original.Status)
|
||||
converted := &authorizationv1beta1.SubjectAccessReview{
|
||||
Spec: v1SpecToV1beta1Spec(&original.Spec),
|
||||
Status: v1StatusToV1beta1Status(original.Status),
|
||||
|
|
Loading…
Reference in New Issue