Skip to content

Commit fad9d55

Browse files
authored
move all fuzz stuff to _test files (#9726)
* move all fuzz stuff to _test files * more opts
1 parent 3d688e7 commit fad9d55

File tree

2 files changed

+66
-89
lines changed

2 files changed

+66
-89
lines changed

pkg/apis/serving/v1/fuzzer.go

-85
This file was deleted.

pkg/apis/serving/v1/roundtrip_test.go

+66-4
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,82 @@ package v1
1919
import (
2020
"testing"
2121

22+
fuzz "github.com/google/gofuzz"
23+
corev1 "k8s.io/api/core/v1"
2224
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
2325
"k8s.io/apimachinery/pkg/runtime"
26+
"k8s.io/apimachinery/pkg/runtime/serializer"
2427
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2528
pkgfuzzer "knative.dev/pkg/apis/testing/fuzzer"
2629
"knative.dev/pkg/apis/testing/roundtrip"
2730
)
2831

32+
// fuzzerFuncs includes fuzzing funcs for knative.dev/serving v1 types
33+
//
34+
// For other examples see
35+
// https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/fuzzer/fuzzer.go
36+
var fuzzerFuncs = fuzzer.MergeFuzzerFuncs(
37+
pkgfuzzer.Funcs,
38+
fuzzer.MergeFuzzerFuncs(
39+
func(codecs serializer.CodecFactory) []interface{} {
40+
return []interface{}{
41+
func(s *ConfigurationStatus, c fuzz.Continue) {
42+
c.FuzzNoCustom(s) // fuzz the status object
43+
44+
// Clear the random fuzzed condition
45+
s.Status.SetConditions(nil)
46+
47+
// Fuzz the known conditions except their type value
48+
s.InitializeConditions()
49+
pkgfuzzer.FuzzConditions(&s.Status, c)
50+
},
51+
func(s *RevisionStatus, c fuzz.Continue) {
52+
c.FuzzNoCustom(s) // fuzz the status object
53+
54+
// Clear the random fuzzed condition
55+
s.Status.SetConditions(nil)
56+
57+
// Fuzz the known conditions except their type value
58+
s.InitializeConditions()
59+
pkgfuzzer.FuzzConditions(&s.Status, c)
60+
},
61+
func(s *RouteStatus, c fuzz.Continue) {
62+
c.FuzzNoCustom(s) // fuzz the status object
63+
64+
// Clear the random fuzzed condition
65+
s.Status.SetConditions(nil)
66+
67+
// Fuzz the known conditions except their type value
68+
s.InitializeConditions()
69+
pkgfuzzer.FuzzConditions(&s.Status, c)
70+
},
71+
func(s *ServiceStatus, c fuzz.Continue) {
72+
c.FuzzNoCustom(s) // fuzz the status object
73+
74+
// Clear the random fuzzed condition
75+
s.Status.SetConditions(nil)
76+
77+
// Fuzz the known conditions except their type value
78+
s.InitializeConditions()
79+
pkgfuzzer.FuzzConditions(&s.Status, c)
80+
},
81+
func(ps *corev1.PodSpec, c fuzz.Continue) {
82+
c.FuzzNoCustom(ps)
83+
84+
if len(ps.Containers) == 0 {
85+
// There must be at least 1 container.
86+
ps.Containers = append(ps.Containers, corev1.Container{})
87+
c.Fuzz(&ps.Containers[0])
88+
}
89+
},
90+
}
91+
},
92+
),
93+
)
94+
2995
func TestServingRoundTripTypesToJSON(t *testing.T) {
3096
scheme := runtime.NewScheme()
3197
utilruntime.Must(AddToScheme(scheme))
3298

33-
fuzzerFuncs := fuzzer.MergeFuzzerFuncs(
34-
pkgfuzzer.Funcs,
35-
FuzzerFuncs,
36-
)
3799
roundtrip.ExternalTypesViaJSON(t, scheme, fuzzerFuncs)
38100
}

0 commit comments

Comments
 (0)