FuzzFromBytesFunc is a fuzz testing suite that exercises the FromBytes function
(f *testing.F)
| 425 | |
| 426 | // FuzzFromBytesFunc is a fuzz testing suite that exercises the FromBytes function |
| 427 | func FuzzFromBytesFunc(f *testing.F) { |
| 428 | for _, seed := range fromBytesCorpus { |
| 429 | f.Add(seed) |
| 430 | } |
| 431 | uuidRegexp, err := regexp.Compile(uuidPattern) |
| 432 | if err != nil { |
| 433 | f.Fatal("uuid regexp failed to compile") |
| 434 | } |
| 435 | f.Fuzz(func(t *testing.T, payload []byte) { |
| 436 | u, err := FromBytes(payload) |
| 437 | if len(payload) != Size && err == nil { |
| 438 | t.Errorf("%v did not result in an error", payload) |
| 439 | } |
| 440 | if len(payload) == Size && u == Nil { |
| 441 | t.Errorf("%v resulted in Nil uuid", payload) |
| 442 | } |
| 443 | if len(payload) == Size && !uuidRegexp.MatchString(u.String()) { |
| 444 | t.Errorf("%v resulted in invalid uuid %s", payload, u.String()) |
| 445 | } |
| 446 | // otherwise, allow to pass if no panic |
| 447 | }) |
| 448 | } |
| 449 | |
| 450 | // FuzzFromBytesOrNilFunc is a fuzz testing suite that exercises the FromBytesOrNil function |
| 451 | func FuzzFromBytesOrNilFunc(f *testing.F) { |