2020-07-08 17:31:57 +00:00
|
|
|
package media_test
|
2020-07-06 11:29:44 +00:00
|
|
|
|
|
|
|
import (
|
2020-07-08 17:31:57 +00:00
|
|
|
"segmento/pkg/media"
|
2020-07-06 11:29:44 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-07-08 17:31:57 +00:00
|
|
|
func TestSegmenterImplements(t *testing.T) {
|
|
|
|
require.Implements(t, (*media.Segmenter)(nil), new(media.MP3Segmenter))
|
|
|
|
}
|
|
|
|
|
2020-07-06 11:29:44 +00:00
|
|
|
func TestSegment(t *testing.T) {
|
2020-07-08 17:31:57 +00:00
|
|
|
segment := media.NewSegment(10*time.Second, 0)
|
2020-07-06 11:29:44 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|