@@ -19,9 +19,12 @@ package v1alpha7
19
19
import (
20
20
"testing"
21
21
22
+ fuzz "github.com/google/gofuzz"
22
23
"github.com/onsi/gomega"
24
+ "k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
23
25
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24
26
runtime "k8s.io/apimachinery/pkg/runtime"
27
+ runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
25
28
"k8s.io/utils/pointer"
26
29
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
27
30
"sigs.k8s.io/controller-runtime/pkg/conversion"
@@ -52,60 +55,89 @@ func TestFuzzyConversion(t *testing.T) {
52
55
delete (obj .GetAnnotations (), utilconversion .DataAnnotation )
53
56
}
54
57
58
+ fuzzerFuncs := func (_ runtimeserializer.CodecFactory ) []interface {} {
59
+ return []interface {}{
60
+ func (spec * infrav1.OpenStackClusterSpec , c fuzz.Continue ) {
61
+ c .FuzzNoCustom (spec )
62
+
63
+ // The fuzzer only seems to generate Subnets of
64
+ // length 1, but we need to also test length 2.
65
+ // Ensure it is occasionally generated.
66
+ if len (spec .Subnets ) == 1 && c .RandBool () {
67
+ subnet := infrav1.SubnetFilter {}
68
+ c .FuzzNoCustom (& subnet )
69
+ spec .Subnets = append (spec .Subnets , subnet )
70
+ }
71
+ },
72
+ }
73
+ }
74
+
55
75
t .Run ("for OpenStackCluster" , runParallel (utilconversion .FuzzTestFunc (utilconversion.FuzzTestFuncInput {
56
76
Hub : & infrav1.OpenStackCluster {},
57
77
Spoke : & OpenStackCluster {},
58
78
HubAfterMutation : ignoreDataAnnotation ,
79
+ FuzzerFuncs : []fuzzer.FuzzerFuncs {fuzzerFuncs },
59
80
})))
60
81
61
82
t .Run ("for OpenStackCluster with mutate" , runParallel (testhelpers .FuzzMutateTestFunc (testhelpers.FuzzMutateTestFuncInput {
62
83
FuzzTestFuncInput : utilconversion.FuzzTestFuncInput {
63
84
Hub : & infrav1.OpenStackCluster {},
64
85
Spoke : & OpenStackCluster {},
65
86
HubAfterMutation : ignoreDataAnnotation ,
87
+ FuzzerFuncs : []fuzzer.FuzzerFuncs {fuzzerFuncs },
66
88
},
89
+ MutateFuzzerFuncs : []fuzzer.FuzzerFuncs {fuzzerFuncs },
67
90
})))
68
91
69
92
t .Run ("for OpenStackClusterTemplate" , runParallel (utilconversion .FuzzTestFunc (utilconversion.FuzzTestFuncInput {
70
93
Hub : & infrav1.OpenStackClusterTemplate {},
71
94
Spoke : & OpenStackClusterTemplate {},
72
95
HubAfterMutation : ignoreDataAnnotation ,
96
+ FuzzerFuncs : []fuzzer.FuzzerFuncs {fuzzerFuncs },
73
97
})))
74
98
75
99
t .Run ("for OpenStackClusterTemplate with mutate" , runParallel (testhelpers .FuzzMutateTestFunc (testhelpers.FuzzMutateTestFuncInput {
76
100
FuzzTestFuncInput : utilconversion.FuzzTestFuncInput {
77
101
Hub : & infrav1.OpenStackClusterTemplate {},
78
102
Spoke : & OpenStackClusterTemplate {},
79
103
HubAfterMutation : ignoreDataAnnotation ,
104
+ FuzzerFuncs : []fuzzer.FuzzerFuncs {fuzzerFuncs },
80
105
},
106
+ MutateFuzzerFuncs : []fuzzer.FuzzerFuncs {fuzzerFuncs },
81
107
})))
82
108
83
109
t .Run ("for OpenStackMachine" , runParallel (utilconversion .FuzzTestFunc (utilconversion.FuzzTestFuncInput {
84
110
Hub : & infrav1.OpenStackMachine {},
85
111
Spoke : & OpenStackMachine {},
86
112
HubAfterMutation : ignoreDataAnnotation ,
113
+ FuzzerFuncs : []fuzzer.FuzzerFuncs {fuzzerFuncs },
87
114
})))
88
115
89
116
t .Run ("for OpenStackMachine with mutate" , runParallel (testhelpers .FuzzMutateTestFunc (testhelpers.FuzzMutateTestFuncInput {
90
117
FuzzTestFuncInput : utilconversion.FuzzTestFuncInput {
91
118
Hub : & infrav1.OpenStackMachine {},
92
119
Spoke : & OpenStackMachine {},
93
120
HubAfterMutation : ignoreDataAnnotation ,
121
+ FuzzerFuncs : []fuzzer.FuzzerFuncs {fuzzerFuncs },
94
122
},
123
+ MutateFuzzerFuncs : []fuzzer.FuzzerFuncs {fuzzerFuncs },
95
124
})))
96
125
97
126
t .Run ("for OpenStackMachineTemplate" , runParallel (utilconversion .FuzzTestFunc (utilconversion.FuzzTestFuncInput {
98
127
Hub : & infrav1.OpenStackMachineTemplate {},
99
128
Spoke : & OpenStackMachineTemplate {},
100
129
HubAfterMutation : ignoreDataAnnotation ,
130
+ FuzzerFuncs : []fuzzer.FuzzerFuncs {fuzzerFuncs },
101
131
})))
102
132
103
133
t .Run ("for OpenStackMachineTemplate with mutate" , runParallel (testhelpers .FuzzMutateTestFunc (testhelpers.FuzzMutateTestFuncInput {
104
134
FuzzTestFuncInput : utilconversion.FuzzTestFuncInput {
105
135
Hub : & infrav1.OpenStackMachineTemplate {},
106
136
Spoke : & OpenStackMachineTemplate {},
107
137
HubAfterMutation : ignoreDataAnnotation ,
138
+ FuzzerFuncs : []fuzzer.FuzzerFuncs {fuzzerFuncs },
108
139
},
140
+ MutateFuzzerFuncs : []fuzzer.FuzzerFuncs {fuzzerFuncs },
109
141
})))
110
142
}
111
143
0 commit comments