Skip to content

Commit

Permalink
chore(tests): add Fuzz tests (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz authored Aug 22, 2023
1 parent 06716f6 commit 542ddab
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,39 @@ func TestIsWrongLength(t *testing.T) {
}
}

func FuzzParse(f *testing.F) {
for _, tt := range tests {
f.Add(tt.in)
f.Add(strings.ToUpper(tt.in))
}
f.Fuzz(func(t *testing.T, in string) {
Parse(in)
})
}

func FuzzParseBytes(f *testing.F) {
for _, tt := range tests {
f.Add([]byte(tt.in))
}
f.Fuzz(func(t *testing.T, in []byte) {
ParseBytes(in)
})
}

func FuzzFromBytes(f *testing.F) {
// Copied from TestFromBytes.
f.Add([]byte{
0x7d, 0x44, 0x48, 0x40,
0x9d, 0xc0,
0x11, 0xd1,
0xb2, 0x45,
0x5f, 0xfd, 0xce, 0x74, 0xfa, 0xd2,
})
f.Fuzz(func(t *testing.T, in []byte) {
FromBytes(in)
})
}

var asString = "f47ac10b-58cc-0372-8567-0e02b2c3d479"
var asBytes = []byte(asString)

Expand Down

0 comments on commit 542ddab

Please # to comment.