@@ -19,8 +19,8 @@ package helpers
1919import (
2020 "strings"
2121
22- fuzz "github.com/google/gofuzz"
2322 "k8s.io/utils/ptr"
23+ "sigs.k8s.io/randfill"
2424
2525 infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta2"
2626 "sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
@@ -37,9 +37,9 @@ func filterInvalidTags(tags []infrav1.NeutronTag) []infrav1.NeutronTag {
3737 return ret
3838}
3939
40- func nonEmptyString (c fuzz .Continue ) string {
40+ func nonEmptyString (c randfill .Continue ) string {
4141 for {
42- if s := c .RandString ( ); s != "" {
42+ if s := c .String ( 20 ); s != "" {
4343 return s
4444 }
4545 }
@@ -50,14 +50,14 @@ type isZeroer[T any] interface {
5050 * T
5151}
5252
53- func fuzzFilterParam [Z isZeroer [T ], T any ](id * optional.String , filter * Z , c fuzz .Continue ) {
54- if c .RandBool () {
53+ func fuzzFilterParam [Z isZeroer [T ], T any ](id * optional.String , filter * Z , c randfill .Continue ) {
54+ if c .Bool () {
5555 * id = ptr .To (nonEmptyString (c ))
5656 * filter = nil
5757 } else {
5858 * filter = new (T )
5959 for (* filter ).IsZero () {
60- c .Fuzz (* filter )
60+ c .Fill (* filter )
6161 }
6262 * id = nil
6363 }
@@ -66,60 +66,60 @@ func fuzzFilterParam[Z isZeroer[T], T any](id *optional.String, filter *Z, c fuz
6666// InfraV1FuzzerFuncs returns fuzzer funcs for v1beta1 OpenStack types which:
6767// * Constrain the output in ways which are validated by the API server
6868// * Add additional test coverage where it is not generated by the default fuzzer.
69- func InfraV1FuzzerFuncs () []interface {} {
70- return []interface {} {
71- func (spec * infrav1.OpenStackClusterSpec , c fuzz .Continue ) {
72- c .FuzzNoCustom (spec )
69+ func InfraV1FuzzerFuncs () []any {
70+ return []any {
71+ func (spec * infrav1.OpenStackClusterSpec , c randfill .Continue ) {
72+ c .FillNoCustom (spec )
7373
7474 // The fuzzer only seems to generate Subnets of
7575 // length 1, but we need to also test length 2.
7676 // Ensure it is occasionally generated.
77- if len (spec .Subnets ) == 1 && c .RandBool () {
77+ if len (spec .Subnets ) == 1 && c .Bool () {
7878 subnet := infrav1.SubnetParam {}
79- c .Fuzz (& subnet )
79+ c .Fill (& subnet )
8080 spec .Subnets = append (spec .Subnets , subnet )
8181 }
8282 },
8383
84- func (spec * infrav1.SubnetSpec , c fuzz .Continue ) {
85- c .FuzzNoCustom (spec )
84+ func (spec * infrav1.SubnetSpec , c randfill .Continue ) {
85+ c .FillNoCustom (spec )
8686
8787 // CIDR is required and API validates that it's present, so
8888 // we force it to always be set.
8989 for spec .CIDR == "" {
90- spec .CIDR = c .RandString ( )
90+ spec .CIDR = c .String ( 20 )
9191 }
9292 },
9393
94- func (pool * infrav1.AllocationPool , c fuzz .Continue ) {
95- c .FuzzNoCustom (pool )
94+ func (pool * infrav1.AllocationPool , c randfill .Continue ) {
95+ c .FillNoCustom (pool )
9696
9797 // Start and End are required properties, let's make sure both are set
9898 for pool .Start == "" {
99- pool .Start = c .RandString ( )
99+ pool .Start = c .String ( 20 )
100100 }
101101
102102 for pool .End == "" {
103- pool .End = c .RandString ( )
103+ pool .End = c .String ( 20 )
104104 }
105105 },
106106
107107 // v1beta1 filter tags cannot contain commas and can't be empty.
108- func (filter * infrav1.FilterByNeutronTags , c fuzz .Continue ) {
109- c .FuzzNoCustom (filter )
108+ func (filter * infrav1.FilterByNeutronTags , c randfill .Continue ) {
109+ c .FillNoCustom (filter )
110110
111111 // Sometimes add an additional tag to ensure we get test coverage of multiple tags
112- if c .RandBool () {
113- filter .Tags = append (filter .Tags , infrav1 .NeutronTag (c .RandString ( )))
112+ if c .Bool () {
113+ filter .Tags = append (filter .Tags , infrav1 .NeutronTag (c .String ( 20 )))
114114 }
115- if c .RandBool () {
116- filter .TagsAny = append (filter .TagsAny , infrav1 .NeutronTag (c .RandString ( )))
115+ if c .Bool () {
116+ filter .TagsAny = append (filter .TagsAny , infrav1 .NeutronTag (c .String ( 20 )))
117117 }
118- if c .RandBool () {
119- filter .NotTags = append (filter .NotTags , infrav1 .NeutronTag (c .RandString ( )))
118+ if c .Bool () {
119+ filter .NotTags = append (filter .NotTags , infrav1 .NeutronTag (c .String ( 20 )))
120120 }
121- if c .RandBool () {
122- filter .NotTagsAny = append (filter .NotTagsAny , infrav1 .NeutronTag (c .RandString ( )))
121+ if c .Bool () {
122+ filter .NotTagsAny = append (filter .NotTagsAny , infrav1 .NeutronTag (c .String ( 20 )))
123123 }
124124
125125 // Remove empty tags and tags with commas
@@ -130,50 +130,46 @@ func InfraV1FuzzerFuncs() []interface{} {
130130 },
131131
132132 // v1beta1 filter params contain exactly one of ID or filter
133- func (param * infrav1.NetworkParam , c fuzz .Continue ) {
133+ func (param * infrav1.NetworkParam , c randfill .Continue ) {
134134 fuzzFilterParam (& param .ID , & param .Filter , c )
135135 },
136136
137- func (param * infrav1.SubnetParam , c fuzz .Continue ) {
137+ func (param * infrav1.SubnetParam , c randfill .Continue ) {
138138 fuzzFilterParam (& param .ID , & param .Filter , c )
139139 },
140140
141- func (param * infrav1.SecurityGroupParam , c fuzz .Continue ) {
141+ func (param * infrav1.SecurityGroupParam , c randfill .Continue ) {
142142 fuzzFilterParam (& param .ID , & param .Filter , c )
143143 },
144144
145- func (param * infrav1.ImageParam , c fuzz .Continue ) {
145+ func (param * infrav1.ImageParam , c randfill .Continue ) {
146146 fuzzFilterParam (& param .ID , & param .Filter , c )
147147 },
148148
149- func (param * infrav1.RouterParam , c fuzz.Continue ) {
150- fuzzFilterParam (& param .ID , & param .Filter , c )
151- },
152-
153- func (param * infrav1.SecurityGroupParam , c fuzz.Continue ) {
149+ func (param * infrav1.RouterParam , c randfill.Continue ) {
154150 fuzzFilterParam (& param .ID , & param .Filter , c )
155151 },
156152
157153 // Ensure VolumeAZ type is valid
158- func (az * infrav1.VolumeAvailabilityZone , c fuzz .Continue ) {
154+ func (az * infrav1.VolumeAvailabilityZone , c randfill .Continue ) {
159155 stringWithoutSpaces := func () string {
160156 for {
161- s := c .RandString ( )
157+ s := c .String ( 20 )
162158 if ! strings .Contains (s , " " ) && s != "" {
163159 return s
164160 }
165161 }
166162 }
167163
168164 // From is defaulted
169- if c .RandBool () {
165+ if c .Bool () {
170166 name := infrav1 .VolumeAZName (stringWithoutSpaces ())
171167 az .Name = & name
172168 return
173169 }
174170
175171 // From is Name
176- if c .RandBool () {
172+ if c .Bool () {
177173 az .From = infrav1 .VolumeAZFromName
178174 name := infrav1 .VolumeAZName (stringWithoutSpaces ())
179175 az .Name = & name
0 commit comments