Skip to content

Commit a2f5e34

Browse files
chore(deps): bump pgregory.net/rapid from 0.4.7 to 0.5.2 (#79)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com>
1 parent 6085cb3 commit a2f5e34

File tree

5 files changed

+51
-50
lines changed

5 files changed

+51
-50
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/google/go-cmp v0.5.9
77
github.com/stretchr/testify v1.8.0
88
google.golang.org/protobuf v1.28.1
9-
pgregory.net/rapid v0.4.7
9+
pgregory.net/rapid v0.5.2
1010
)
1111

1212
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
2121
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2222
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2323
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
24-
pgregory.net/rapid v0.4.7 h1:MTNRktPuv5FNqOO151TM9mDTa+XHcX6ypYeISDVD14g=
25-
pgregory.net/rapid v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
24+
pgregory.net/rapid v0.5.2 h1:zC+jmuzcz5yJvG/igG06aLx8kcGmZY435NcuyhblKjY=
25+
pgregory.net/rapid v0.5.2/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=

internal/fuzz/message.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package fuzz
22

33
import (
44
"fmt"
5-
"google.golang.org/protobuf/reflect/protoreflect"
65
"math"
6+
7+
"google.golang.org/protobuf/reflect/protoreflect"
78
"pgregory.net/rapid"
89
)
910

@@ -66,7 +67,7 @@ func (g *generator) generate() {
6667
case true:
6768
g.field(fd)
6869
default:
69-
genField := rapid.Bool().Draw(g.t, fmt.Sprintf("skip field generation: %s", fd.FullName())).(bool)
70+
genField := rapid.Bool().Draw(g.t, fmt.Sprintf("skip field generation: %s", fd.FullName()))
7071
if !genField {
7172
continue
7273
}
@@ -83,7 +84,7 @@ func (g *generator) field(fd protoreflect.FieldDescriptor) {
8384
return
8485
}
8586
// check if we can set an invalid value
86-
if g.invalidValue && rapid.Bool().Draw(g.t, fmt.Sprintf("generate invalid value for field %s", fd.FullName())).(bool) {
87+
if g.invalidValue && rapid.Bool().Draw(g.t, fmt.Sprintf("generate invalid value for field %s", fd.FullName())) {
8788
g.m.Set(fd, protoreflect.Value{})
8889
}
8990

@@ -103,7 +104,7 @@ func isOneof(fd protoreflect.FieldDescriptor) bool {
103104

104105
func (g *generator) list(fd protoreflect.FieldDescriptor) {
105106
list := g.m.NewField(fd).List()
106-
length := rapid.IntRange(0, g.maxListLength).Draw(g.t, fmt.Sprintf("list length for %s", fd.FullName())).(int)
107+
length := rapid.IntRange(0, g.maxListLength).Draw(g.t, fmt.Sprintf("list length for %s", fd.FullName()))
107108

108109
for i := 0; i < length; i++ {
109110
switch fd.Kind() {
@@ -124,7 +125,7 @@ func (g *generator) mapp(fd protoreflect.FieldDescriptor) {
124125

125126
mapValue := g.m.NewField(fd).Map()
126127

127-
length := rapid.IntRange(0, g.maxMapLength).Draw(g.t, "map length for "+string(fd.FullName())).(int)
128+
length := rapid.IntRange(0, g.maxMapLength).Draw(g.t, "map length for "+string(fd.FullName()))
128129

129130
for i := 0; i < length; i++ {
130131
keyValue := protoreflect.MapKey(g.valueFor(keyDesc))
@@ -161,43 +162,43 @@ func (g *generator) valueFor(fd protoreflect.FieldDescriptor) protoreflect.Value
161162
switch fd.Kind() {
162163
// bool kind
163164
case protoreflect.BoolKind:
164-
value := rapid.Bool().Draw(g.t, label(fd)).(bool)
165+
value := rapid.Bool().Draw(g.t, label(fd))
165166
return protoreflect.ValueOfBool(value)
166167
// int32 kinds
167168
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
168-
value := rapid.Int32().Draw(g.t, label(fd)).(int32)
169+
value := rapid.Int32().Draw(g.t, label(fd))
169170
return protoreflect.ValueOfInt32(value)
170171
// int64 kinds
171172
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
172-
value := rapid.Int64().Draw(g.t, label(fd)).(int64)
173+
value := rapid.Int64().Draw(g.t, label(fd))
173174
return protoreflect.ValueOfInt64(value)
174175
// uint32 kinds
175176
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
176-
value := rapid.Uint32().Draw(g.t, label(fd)).(uint32)
177+
value := rapid.Uint32().Draw(g.t, label(fd))
177178
return protoreflect.ValueOfUint32(value)
178179
// uint64 kinds
179180
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
180-
value := rapid.Uint64().Draw(g.t, label(fd)).(uint64)
181+
value := rapid.Uint64().Draw(g.t, label(fd))
181182
return protoreflect.ValueOfUint64(value)
182183
// float32 kind
183184
case protoreflect.FloatKind:
184-
value := rapid.Float32Max(math.MaxFloat32).Draw(g.t, label(fd)).(float32)
185+
value := rapid.Float32Max(math.MaxFloat32).Draw(g.t, label(fd))
185186
return protoreflect.ValueOfFloat32(value)
186187
// float64 kind
187188
case protoreflect.DoubleKind:
188-
value := rapid.Float64().Draw(g.t, label(fd)).(float64)
189+
value := rapid.Float64().Draw(g.t, label(fd))
189190
return protoreflect.ValueOfFloat64(value)
190191
// string kind
191192
case protoreflect.StringKind:
192-
value := rapid.String().Draw(g.t, label(fd)).(string)
193+
value := rapid.String().Draw(g.t, label(fd))
193194
return protoreflect.ValueOfString(value)
194195
// bytes kind
195196
case protoreflect.BytesKind:
196197
value := randomBytes(g.t, fd)
197198
return protoreflect.ValueOfBytes(value)
198199
// enum kind
199200
case protoreflect.EnumKind:
200-
enumIndex := rapid.IntRange(0, fd.Enum().Values().Len()-1).Draw(g.t, "random enum index for "+string(fd.FullName())).(int)
201+
enumIndex := rapid.IntRange(0, fd.Enum().Values().Len()-1).Draw(g.t, "random enum index for "+string(fd.FullName()))
201202
enum := fd.Enum().Values().Get(enumIndex)
202203
return protoreflect.ValueOfEnum(enum.Number())
203204
default:
@@ -231,7 +232,7 @@ func (g *generator) decideOneofs() {
231232
md := g.typ.Descriptor()
232233
for i := 0; i < md.Oneofs().Len(); i++ {
233234
oneof := md.Oneofs().Get(i)
234-
index := rapid.IntRange(0, oneof.Fields().Len()-1).Draw(g.t, "deciding oneof field for: "+string(oneof.FullName())).(int)
235+
index := rapid.IntRange(0, oneof.Fields().Len()-1).Draw(g.t, "deciding oneof field for: "+string(oneof.FullName()))
235236
decidedFd := oneof.Fields().Get(index)
236237
g.pickedOneofs[oneof.FullName()] = decidedFd.FullName()
237238
}
@@ -248,6 +249,6 @@ func label(fd protoreflect.FieldDescriptor) string {
248249
}
249250

250251
func randomBytes(t *rapid.T, fd protoreflect.FieldDescriptor) []byte {
251-
size := rapid.IntRange(0, MaxBytesArraySize).Draw(t, "bytes slice size for %s"+string(fd.FullName())).(int)
252-
return rapid.SliceOfN(rapid.Byte(), 0, size).Draw(t, "bytes slice for %s"+string(fd.FullName())).([]byte)
252+
size := rapid.IntRange(0, MaxBytesArraySize).Draw(t, "bytes slice size for %s"+string(fd.FullName()))
253+
return rapid.SliceOfN(rapid.Byte(), 0, size).Draw(t, "bytes slice for %s"+string(fd.FullName()))
253254
}

support/timepb/cmp_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ func TestAddFuzzy(t *testing.T) {
8585
}
8686
gen := rapid.Int64Range(0, 1<<62)
8787
genNano := rapid.Int64Range(0, 1e9-1)
88-
rInt := func(t *rapid.T, label string) int64 { return gen.Draw(t, label).(int64) }
88+
rInt := func(t *rapid.T, label string) int64 { return gen.Draw(t, label) }
8989

9090
rapid.Check(t, func(t *rapid.T) {
91-
s, n, d := rInt(t, "sec"), genNano.Draw(t, "nanos").(int64), time.Duration(rInt(t, "dur"))
91+
s, n, d := rInt(t, "sec"), genNano.Draw(t, "nanos"), time.Duration(rInt(t, "dur"))
9292
check(t, s, n, d)
9393
})
9494

testpb/proto_methods_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,54 +135,54 @@ func populateDynamicMsg(dyn *dynamicpb.Message, msg protoreflect.Message) {
135135

136136
func getRapidMsg(t *rapid.T) A {
137137
return A{
138-
Enum: Enumeration(rapid.IntRange(0, 1).Draw(t, "enum").(int)),
139-
SomeBoolean: rapid.Bool().Draw(t, "SomeBool").(bool),
140-
INT32: rapid.Int32().Draw(t, "INT32").(int32),
141-
SINT32: rapid.Int32().Draw(t, "SINT32").(int32),
142-
UINT32: rapid.Uint32().Draw(t, "UINT32").(uint32),
143-
INT64: rapid.Int64().Draw(t, "INT64").(int64),
144-
SING64: rapid.Int64().Draw(t, "SING64").(int64),
145-
UINT64: rapid.Uint64().Draw(t, "UINT64").(uint64),
146-
SFIXED32: rapid.Int32().Draw(t, "SFIXED32").(int32),
147-
FIXED32: rapid.Uint32().Draw(t, "FIXED32").(uint32),
148-
FLOAT: rapid.Float32().Draw(t, "FLOAT").(float32),
149-
SFIXED64: rapid.Int64().Draw(t, "SFIXED64").(int64),
150-
FIXED64: rapid.Uint64().Draw(t, "FIXED64").(uint64),
151-
DOUBLE: rapid.Float64().Draw(t, "DOUBLE").(float64),
152-
STRING: rapid.String().Draw(t, "STRING").(string),
153-
BYTES: rapid.SliceOf(rapid.Byte()).Draw(t, "byte slice").([]byte),
154-
MESSAGE: genMessageB.Draw(t, "MESSAGE").(*B),
155-
LIST: rapid.SliceOf(genMessageB).Draw(t, "LIST").([]*B),
156-
ONEOF: genOneOf.Draw(t, "one of").(isA_ONEOF),
157-
MAP: rapid.MapOf(rapid.String(), genMessageB).Draw(t, "map[string]*B").(map[string]*B),
158-
LIST_ENUM: rapid.SliceOf(genEnumSlice).Draw(t, "slice enum").([]Enumeration),
138+
Enum: Enumeration(rapid.IntRange(0, 1).Draw(t, "enum")),
139+
SomeBoolean: rapid.Bool().Draw(t, "SomeBool"),
140+
INT32: rapid.Int32().Draw(t, "INT32"),
141+
SINT32: rapid.Int32().Draw(t, "SINT32"),
142+
UINT32: rapid.Uint32().Draw(t, "UINT32"),
143+
INT64: rapid.Int64().Draw(t, "INT64"),
144+
SING64: rapid.Int64().Draw(t, "SING64"),
145+
UINT64: rapid.Uint64().Draw(t, "UINT64"),
146+
SFIXED32: rapid.Int32().Draw(t, "SFIXED32"),
147+
FIXED32: rapid.Uint32().Draw(t, "FIXED32"),
148+
FLOAT: rapid.Float32().Draw(t, "FLOAT"),
149+
SFIXED64: rapid.Int64().Draw(t, "SFIXED64"),
150+
FIXED64: rapid.Uint64().Draw(t, "FIXED64"),
151+
DOUBLE: rapid.Float64().Draw(t, "DOUBLE"),
152+
STRING: rapid.String().Draw(t, "STRING"),
153+
BYTES: rapid.SliceOf(rapid.Byte()).Draw(t, "byte slice"),
154+
MESSAGE: genMessageB.Draw(t, "MESSAGE"),
155+
LIST: rapid.SliceOf(genMessageB).Draw(t, "LIST"),
156+
ONEOF: genOneOf.Draw(t, "one of"),
157+
MAP: rapid.MapOf(rapid.String(), genMessageB).Draw(t, "map[string]*B"),
158+
LIST_ENUM: rapid.SliceOf(genEnumSlice).Draw(t, "slice enum"),
159159
}
160160
}
161161

162162
var genEnumSlice = rapid.Custom(func(t *rapid.T) Enumeration {
163-
n := rapid.Int32Range(0, 1).Draw(t, "int32").(int32)
163+
n := rapid.Int32Range(0, 1).Draw(t, "int32")
164164
return Enumeration(n)
165165
})
166166

167167
var genOneOf = rapid.Custom(func(t *rapid.T) isA_ONEOF {
168-
oneof := rapid.OneOf(genOneOfB, genOneOfString).Draw(t, "oneof").(isA_ONEOF)
168+
oneof := rapid.OneOf(genOneOfB, genOneOfString).Draw(t, "oneof")
169169
return oneof
170170
})
171171

172-
var genOneOfB = rapid.Custom(func(t *rapid.T) *A_ONEOF_B {
173-
return &A_ONEOF_B{ONEOF_B: genMessageB.Draw(t, "message B in one of").(*B)}
172+
var genOneOfB = rapid.Custom(func(t *rapid.T) isA_ONEOF {
173+
return &A_ONEOF_B{ONEOF_B: genMessageB.Draw(t, "message B in one of")}
174174
})
175175

176-
var genOneOfString = rapid.Custom(func(t *rapid.T) *A_ONEOF_STRING {
177-
return &A_ONEOF_STRING{ONEOF_STRING: rapid.StringN(1, -1, -1).Draw(t, "string in one of").(string)}
176+
var genOneOfString = rapid.Custom(func(t *rapid.T) isA_ONEOF {
177+
return &A_ONEOF_STRING{ONEOF_STRING: rapid.StringN(1, -1, -1).Draw(t, "string in one of")}
178178
})
179179

180180
var genMessageB = rapid.Custom(func(t *rapid.T) *B {
181181
msg := B{
182182
state: protoimpl.MessageState{},
183183
sizeCache: 0,
184184
unknownFields: nil,
185-
X: rapid.String().Draw(t, "X").(string),
185+
X: rapid.String().Draw(t, "X"),
186186
}
187187
return &msg
188188
})

0 commit comments

Comments
 (0)