Skip to content

Commit

Permalink
chore(tests): add Fuzz tests (google#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz authored and tkarrass committed Sep 11, 2024
1 parent 9cebf06 commit ef4fa67
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 ef4fa67

Please sign in to comment.