@@ -19,20 +19,82 @@ package v1
19
19
import (
20
20
"testing"
21
21
22
+ fuzz "github.com/google/gofuzz"
23
+ corev1 "k8s.io/api/core/v1"
22
24
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
23
25
"k8s.io/apimachinery/pkg/runtime"
26
+ "k8s.io/apimachinery/pkg/runtime/serializer"
24
27
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
25
28
pkgfuzzer "knative.dev/pkg/apis/testing/fuzzer"
26
29
"knative.dev/pkg/apis/testing/roundtrip"
27
30
)
28
31
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
+
29
95
func TestServingRoundTripTypesToJSON (t * testing.T ) {
30
96
scheme := runtime .NewScheme ()
31
97
utilruntime .Must (AddToScheme (scheme ))
32
98
33
- fuzzerFuncs := fuzzer .MergeFuzzerFuncs (
34
- pkgfuzzer .Funcs ,
35
- FuzzerFuncs ,
36
- )
37
99
roundtrip .ExternalTypesViaJSON (t , scheme , fuzzerFuncs )
38
100
}
0 commit comments