Skip to content

Commit

Permalink
chore(deps): bump pgregory.net/rapid from 0.4.7 to 0.5.2 (#79)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
3 people authored Sep 9, 2022
1 parent 6085cb3 commit a2f5e34
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 50 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/google/go-cmp v0.5.9
github.com/stretchr/testify v1.8.0
google.golang.org/protobuf v1.28.1
pgregory.net/rapid v0.4.7
pgregory.net/rapid v0.5.2
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
pgregory.net/rapid v0.4.7 h1:MTNRktPuv5FNqOO151TM9mDTa+XHcX6ypYeISDVD14g=
pgregory.net/rapid v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
pgregory.net/rapid v0.5.2 h1:zC+jmuzcz5yJvG/igG06aLx8kcGmZY435NcuyhblKjY=
pgregory.net/rapid v0.5.2/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
35 changes: 18 additions & 17 deletions internal/fuzz/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package fuzz

import (
"fmt"
"google.golang.org/protobuf/reflect/protoreflect"
"math"

"google.golang.org/protobuf/reflect/protoreflect"
"pgregory.net/rapid"
)

Expand Down Expand Up @@ -66,7 +67,7 @@ func (g *generator) generate() {
case true:
g.field(fd)
default:
genField := rapid.Bool().Draw(g.t, fmt.Sprintf("skip field generation: %s", fd.FullName())).(bool)
genField := rapid.Bool().Draw(g.t, fmt.Sprintf("skip field generation: %s", fd.FullName()))
if !genField {
continue
}
Expand All @@ -83,7 +84,7 @@ func (g *generator) field(fd protoreflect.FieldDescriptor) {
return
}
// check if we can set an invalid value
if g.invalidValue && rapid.Bool().Draw(g.t, fmt.Sprintf("generate invalid value for field %s", fd.FullName())).(bool) {
if g.invalidValue && rapid.Bool().Draw(g.t, fmt.Sprintf("generate invalid value for field %s", fd.FullName())) {
g.m.Set(fd, protoreflect.Value{})
}

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

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

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

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

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

for i := 0; i < length; i++ {
keyValue := protoreflect.MapKey(g.valueFor(keyDesc))
Expand Down Expand Up @@ -161,43 +162,43 @@ func (g *generator) valueFor(fd protoreflect.FieldDescriptor) protoreflect.Value
switch fd.Kind() {
// bool kind
case protoreflect.BoolKind:
value := rapid.Bool().Draw(g.t, label(fd)).(bool)
value := rapid.Bool().Draw(g.t, label(fd))
return protoreflect.ValueOfBool(value)
// int32 kinds
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
value := rapid.Int32().Draw(g.t, label(fd)).(int32)
value := rapid.Int32().Draw(g.t, label(fd))
return protoreflect.ValueOfInt32(value)
// int64 kinds
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
value := rapid.Int64().Draw(g.t, label(fd)).(int64)
value := rapid.Int64().Draw(g.t, label(fd))
return protoreflect.ValueOfInt64(value)
// uint32 kinds
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
value := rapid.Uint32().Draw(g.t, label(fd)).(uint32)
value := rapid.Uint32().Draw(g.t, label(fd))
return protoreflect.ValueOfUint32(value)
// uint64 kinds
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
value := rapid.Uint64().Draw(g.t, label(fd)).(uint64)
value := rapid.Uint64().Draw(g.t, label(fd))
return protoreflect.ValueOfUint64(value)
// float32 kind
case protoreflect.FloatKind:
value := rapid.Float32Max(math.MaxFloat32).Draw(g.t, label(fd)).(float32)
value := rapid.Float32Max(math.MaxFloat32).Draw(g.t, label(fd))
return protoreflect.ValueOfFloat32(value)
// float64 kind
case protoreflect.DoubleKind:
value := rapid.Float64().Draw(g.t, label(fd)).(float64)
value := rapid.Float64().Draw(g.t, label(fd))
return protoreflect.ValueOfFloat64(value)
// string kind
case protoreflect.StringKind:
value := rapid.String().Draw(g.t, label(fd)).(string)
value := rapid.String().Draw(g.t, label(fd))
return protoreflect.ValueOfString(value)
// bytes kind
case protoreflect.BytesKind:
value := randomBytes(g.t, fd)
return protoreflect.ValueOfBytes(value)
// enum kind
case protoreflect.EnumKind:
enumIndex := rapid.IntRange(0, fd.Enum().Values().Len()-1).Draw(g.t, "random enum index for "+string(fd.FullName())).(int)
enumIndex := rapid.IntRange(0, fd.Enum().Values().Len()-1).Draw(g.t, "random enum index for "+string(fd.FullName()))
enum := fd.Enum().Values().Get(enumIndex)
return protoreflect.ValueOfEnum(enum.Number())
default:
Expand Down Expand Up @@ -231,7 +232,7 @@ func (g *generator) decideOneofs() {
md := g.typ.Descriptor()
for i := 0; i < md.Oneofs().Len(); i++ {
oneof := md.Oneofs().Get(i)
index := rapid.IntRange(0, oneof.Fields().Len()-1).Draw(g.t, "deciding oneof field for: "+string(oneof.FullName())).(int)
index := rapid.IntRange(0, oneof.Fields().Len()-1).Draw(g.t, "deciding oneof field for: "+string(oneof.FullName()))
decidedFd := oneof.Fields().Get(index)
g.pickedOneofs[oneof.FullName()] = decidedFd.FullName()
}
Expand All @@ -248,6 +249,6 @@ func label(fd protoreflect.FieldDescriptor) string {
}

func randomBytes(t *rapid.T, fd protoreflect.FieldDescriptor) []byte {
size := rapid.IntRange(0, MaxBytesArraySize).Draw(t, "bytes slice size for %s"+string(fd.FullName())).(int)
return rapid.SliceOfN(rapid.Byte(), 0, size).Draw(t, "bytes slice for %s"+string(fd.FullName())).([]byte)
size := rapid.IntRange(0, MaxBytesArraySize).Draw(t, "bytes slice size for %s"+string(fd.FullName()))
return rapid.SliceOfN(rapid.Byte(), 0, size).Draw(t, "bytes slice for %s"+string(fd.FullName()))
}
4 changes: 2 additions & 2 deletions support/timepb/cmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ func TestAddFuzzy(t *testing.T) {
}
gen := rapid.Int64Range(0, 1<<62)
genNano := rapid.Int64Range(0, 1e9-1)
rInt := func(t *rapid.T, label string) int64 { return gen.Draw(t, label).(int64) }
rInt := func(t *rapid.T, label string) int64 { return gen.Draw(t, label) }

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

Expand Down
56 changes: 28 additions & 28 deletions testpb/proto_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,54 +135,54 @@ func populateDynamicMsg(dyn *dynamicpb.Message, msg protoreflect.Message) {

func getRapidMsg(t *rapid.T) A {
return A{
Enum: Enumeration(rapid.IntRange(0, 1).Draw(t, "enum").(int)),
SomeBoolean: rapid.Bool().Draw(t, "SomeBool").(bool),
INT32: rapid.Int32().Draw(t, "INT32").(int32),
SINT32: rapid.Int32().Draw(t, "SINT32").(int32),
UINT32: rapid.Uint32().Draw(t, "UINT32").(uint32),
INT64: rapid.Int64().Draw(t, "INT64").(int64),
SING64: rapid.Int64().Draw(t, "SING64").(int64),
UINT64: rapid.Uint64().Draw(t, "UINT64").(uint64),
SFIXED32: rapid.Int32().Draw(t, "SFIXED32").(int32),
FIXED32: rapid.Uint32().Draw(t, "FIXED32").(uint32),
FLOAT: rapid.Float32().Draw(t, "FLOAT").(float32),
SFIXED64: rapid.Int64().Draw(t, "SFIXED64").(int64),
FIXED64: rapid.Uint64().Draw(t, "FIXED64").(uint64),
DOUBLE: rapid.Float64().Draw(t, "DOUBLE").(float64),
STRING: rapid.String().Draw(t, "STRING").(string),
BYTES: rapid.SliceOf(rapid.Byte()).Draw(t, "byte slice").([]byte),
MESSAGE: genMessageB.Draw(t, "MESSAGE").(*B),
LIST: rapid.SliceOf(genMessageB).Draw(t, "LIST").([]*B),
ONEOF: genOneOf.Draw(t, "one of").(isA_ONEOF),
MAP: rapid.MapOf(rapid.String(), genMessageB).Draw(t, "map[string]*B").(map[string]*B),
LIST_ENUM: rapid.SliceOf(genEnumSlice).Draw(t, "slice enum").([]Enumeration),
Enum: Enumeration(rapid.IntRange(0, 1).Draw(t, "enum")),
SomeBoolean: rapid.Bool().Draw(t, "SomeBool"),
INT32: rapid.Int32().Draw(t, "INT32"),
SINT32: rapid.Int32().Draw(t, "SINT32"),
UINT32: rapid.Uint32().Draw(t, "UINT32"),
INT64: rapid.Int64().Draw(t, "INT64"),
SING64: rapid.Int64().Draw(t, "SING64"),
UINT64: rapid.Uint64().Draw(t, "UINT64"),
SFIXED32: rapid.Int32().Draw(t, "SFIXED32"),
FIXED32: rapid.Uint32().Draw(t, "FIXED32"),
FLOAT: rapid.Float32().Draw(t, "FLOAT"),
SFIXED64: rapid.Int64().Draw(t, "SFIXED64"),
FIXED64: rapid.Uint64().Draw(t, "FIXED64"),
DOUBLE: rapid.Float64().Draw(t, "DOUBLE"),
STRING: rapid.String().Draw(t, "STRING"),
BYTES: rapid.SliceOf(rapid.Byte()).Draw(t, "byte slice"),
MESSAGE: genMessageB.Draw(t, "MESSAGE"),
LIST: rapid.SliceOf(genMessageB).Draw(t, "LIST"),
ONEOF: genOneOf.Draw(t, "one of"),
MAP: rapid.MapOf(rapid.String(), genMessageB).Draw(t, "map[string]*B"),
LIST_ENUM: rapid.SliceOf(genEnumSlice).Draw(t, "slice enum"),
}
}

var genEnumSlice = rapid.Custom(func(t *rapid.T) Enumeration {
n := rapid.Int32Range(0, 1).Draw(t, "int32").(int32)
n := rapid.Int32Range(0, 1).Draw(t, "int32")
return Enumeration(n)
})

var genOneOf = rapid.Custom(func(t *rapid.T) isA_ONEOF {
oneof := rapid.OneOf(genOneOfB, genOneOfString).Draw(t, "oneof").(isA_ONEOF)
oneof := rapid.OneOf(genOneOfB, genOneOfString).Draw(t, "oneof")
return oneof
})

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

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

var genMessageB = rapid.Custom(func(t *rapid.T) *B {
msg := B{
state: protoimpl.MessageState{},
sizeCache: 0,
unknownFields: nil,
X: rapid.String().Draw(t, "X").(string),
X: rapid.String().Draw(t, "X"),
}
return &msg
})

0 comments on commit a2f5e34

Please sign in to comment.