MCPcopy
hub / github.com/gofrs/uuid / FuzzFromBytesFunc

Function FuzzFromBytesFunc

codec_test.go:427–448  ·  view source on GitHub ↗

FuzzFromBytesFunc is a fuzz testing suite that exercises the FromBytes function

(f *testing.F)

Source from the content-addressed store, hash-verified

425
426// FuzzFromBytesFunc is a fuzz testing suite that exercises the FromBytes function
427func 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
451func FuzzFromBytesOrNilFunc(f *testing.F) {

Callers

nothing calls this directly

Calls 2

FromBytesFunction · 0.85
StringMethod · 0.80

Tested by

no test coverage detected