Skip to content

Commit

Permalink
fixed logical errors with fuzz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cameracker committed May 14, 2024
1 parent 453a026 commit 770941f
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,14 @@ func FuzzFromBytesFunc(f *testing.F) {
}
f.Fuzz(func(t *testing.T, payload []byte) {
u, err := FromBytes(payload)
if len(payload) != 16 && err == nil {
if len(payload) != Size && err == nil {
t.Errorf("%v did not result in an error", payload)
} else {
if u == Nil {
t.Errorf("%v resulted in Nil uuid", payload)
}
if !uuidRegexp.MatchString(u.String()) {
t.Errorf("%v resulted in invalid uuid %s", payload, u.String())
}
}
if len(payload) == Size && u == Nil {
t.Errorf("%v resulted in Nil uuid", payload)
}
if len(payload) == Size && !uuidRegexp.MatchString(u.String()) {
t.Errorf("%v resulted in invalid uuid %s", payload, u.String())
}
// otherwise, allow to pass if no panic
})
Expand All @@ -443,13 +442,14 @@ func FuzzFromBytesOrNilFunc(f *testing.F) {
}
f.Fuzz(func(t *testing.T, payload []byte) {
u := FromBytesOrNil(payload)
if len(payload) != 16 && u != Nil {
if len(payload) != Size && u != Nil {
t.Errorf("%v resulted in non Nil uuid %s", payload, u.String())
}
if u != Nil {
if !uuidRegexp.MatchString(u.String()) {
t.Errorf("%v resulted in invalid uuid %s", payload, u.String())
}
if len(payload) == Size && u == Nil {
t.Errorf("%v resulted Nil uuid", payload)
}
if len(payload) == Size && !uuidRegexp.MatchString(u.String()) {
t.Errorf("%v resulted in invalid uuid %s", payload, u.String())
}
// otherwise, allow to pass if no panic
})
Expand Down

0 comments on commit 770941f

Please sign in to comment.