package main import ( "testing" "time" "github.com/stretchr/testify/require" ) func TestSegment(t *testing.T) { segment := newSegment(10*time.Second, 0) require.Equal(t, time.Duration(0), segment.Duration()) require.True(t, segment.CanWrite(9*time.Second)) require.True(t, segment.CanWrite(10*time.Second)) require.False(t, segment.CanWrite(11*time.Second)) d := segment.IncrementDuration(10 * time.Second) require.Equal(t, segment.Duration(), d) require.Equal(t, 10*time.Second, segment.Duration()) require.False(t, segment.CanWrite(1*time.Millisecond)) } func TestMediaPlaylistImplements(t *testing.T) { require.Implements(t, (*Playlist)(nil), newMediaPlaylist()) } func TestMediaPlaylist(t *testing.T) { playlist := newMediaPlaylist() for i := 0; i < 8; i++ { s := newSegment(10*time.Second, 0) s.IncrementDuration(3 * time.Second) playlist.AddSegment(s) } require.Equal(t, 21*time.Second, playlist.Duration()) }