Skip to content

Commit

Permalink
improve fuzz tests (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Aug 1, 2024
1 parent 1518119 commit 307ccc2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pkg/playlist/media_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ func FuzzMediaUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, a string) {
var m Media
m.Unmarshal([]byte(a)) //nolint:errcheck
err := m.Unmarshal([]byte(a))
if err == nil {
m.Marshal() //nolint:errcheck
}
})
}
5 changes: 4 additions & 1 deletion pkg/playlist/multivariant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,9 @@ func FuzzMultivariantUnmarshal(f *testing.F) {

f.Fuzz(func(_ *testing.T, a string) {
var m Multivariant
m.Unmarshal([]byte(a)) //nolint:errcheck
err := m.Unmarshal([]byte(a))
if err == nil {
m.Marshal() //nolint:errcheck
}
})
}
4 changes: 3 additions & 1 deletion pkg/playlist/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ const (

// Playlist is either Media or Multivariant.
type Playlist interface {
isPlaylist()
Unmarshal([]byte) error
Marshal() ([]byte, error)

isPlaylist()
}

func findType(buf []byte) (Playlist, error) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/playlist/playlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func FuzzPlaylistUnmarshal(f *testing.F) {
}

f.Fuzz(func(_ *testing.T, a string) {
Unmarshal([]byte(a)) //nolint:errcheck
pl, err := Unmarshal([]byte(a))
if err == nil {
pl.Marshal() //nolint:errcheck
}
})
}

0 comments on commit 307ccc2

Please sign in to comment.