Skip to content

Commit

Permalink
test: add more negative masterplaylist tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Jan 20, 2025
1 parent 73cdd20 commit 710fbdc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
43 changes: 37 additions & 6 deletions m3u8/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,48 @@ func TestDecodeMasterWithHLSV7(t *testing.T) {
}
}

func TestReadBadSessionData(t *testing.T) {
func TestReadBadMasterPlaylists(t *testing.T) {
is := is.New(t)
pl := `#EXTM3U
cases := []struct {
desc string
playlist string
}{
{
desc: "bad session data",
playlist: `#EXTM3U
#EXT-X-VERSION:7
#EXT-X-SESSION-DATA:DATA-ID="com.example.title",VALUE="This is an example title",FORMAT=bad
#EXT-X-INF:BANDWIDTH=1280000
video.m3u8
`
p := NewMasterPlaylist()
err := p.DecodeFrom(bufio.NewReader(bytes.NewBufferString(pl)), true)
is.True(err != nil) // must return an error
`,
},
{
desc: "bad define",
playlist: `#EXTM3U
#EXT-X-VERSION:7
#EXT-X-DEFINE:NAME="example.com"
#EXT-X-INF:BANDWIDTH=1280000
video.m3u8
`,
},
{
desc: "bad start",
playlist: `#EXTM3U
#EXT-X-VERSION:7
#EXT-X-START:TIME-OFFSET=bad
#EXT-X-INF:BANDWIDTH=1280000
video.m3u8
`,
},
}

for _, c := range cases {
t.Run(c.desc, func(t *testing.T) {
p := NewMasterPlaylist()
err := p.DecodeFrom(bufio.NewReader(bytes.NewBufferString(c.playlist)), true)
is.True(err != nil) // must return an error
})
}
}

/****************************
Expand Down
20 changes: 20 additions & 0 deletions m3u8/structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ func TestSCTE35String(t *testing.T) {
}
}

func TestMapEqual(t *testing.T) {
cases := []struct {
desc string
m1, m2 *Map
equal bool
}{
{desc: "nil vs nil", m1: nil, m2: nil, equal: true},
{desc: "nil vs non-nil", m1: &Map{}, m2: nil, equal: false},
{desc: "equal non-nil", m1: &Map{URI: "a"}, m2: &Map{URI: "a"}, equal: true},
{desc: "non-equal non-nil", m1: &Map{URI: "a"}, m2: &Map{URI: "b"}, equal: false},
}
for _, c := range cases {
t.Run(c.desc, func(t *testing.T) {
if c.m1.Equal(c.m2) != c.equal {
t.Fatalf("Expected %v, got %v for %s", c.equal, c.m1.Equal(c.m2), c.desc)
}
})
}
}

type MockCustomTag struct {
name string
err error
Expand Down

0 comments on commit 710fbdc

Please sign in to comment.