mirror of
https://github.com/owncast/owncast.git
synced 2024-10-10 19:16:02 +00:00
chore(tests): more clip validation tests
This commit is contained in:
parent
ea376477b6
commit
adb67e79b3
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/owncast/owncast/core/data"
|
"github.com/owncast/owncast/core/data"
|
||||||
"github.com/owncast/owncast/db"
|
"github.com/owncast/owncast/db"
|
||||||
|
"github.com/owncast/owncast/utils"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/teris-io/shortid"
|
"github.com/teris-io/shortid"
|
||||||
)
|
)
|
||||||
@ -17,9 +18,12 @@ import (
|
|||||||
var (
|
var (
|
||||||
fakeStreamId = shortid.MustGenerate()
|
fakeStreamId = shortid.MustGenerate()
|
||||||
fakeSegmentCount = 300
|
fakeSegmentCount = 300
|
||||||
fakeSegmentDuration = 4 // Seconds
|
fakeSegmentDuration = 0
|
||||||
fakeStreamStartTime = time.Now()
|
fakeStreamStartTime = time.Now()
|
||||||
fakeConfigId = ""
|
fakeConfigId = ""
|
||||||
|
fakeClipper = shortid.MustGenerate()
|
||||||
|
fakeClipStartTime = 10
|
||||||
|
fakeClipEndTime = 15
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
@ -37,6 +41,7 @@ func populateFakeStream() {
|
|||||||
|
|
||||||
recording := NewRecording(fakeStreamId)
|
recording := NewRecording(fakeStreamId)
|
||||||
fakeConfigId = recording.outputConfigurations[0].ID
|
fakeConfigId = recording.outputConfigurations[0].ID
|
||||||
|
fakeSegmentDuration = data.GetStreamLatencyLevel().SecondsPerSegment // Seconds
|
||||||
|
|
||||||
for i := 0; i < fakeSegmentCount; i++ {
|
for i := 0; i < fakeSegmentCount; i++ {
|
||||||
fakeSegmentName := fmt.Sprintf("%s-%d.ts", fakeStreamId, i)
|
fakeSegmentName := fmt.Sprintf("%s-%d.ts", fakeStreamId, i)
|
||||||
@ -87,3 +92,63 @@ func TestPlaylist(t *testing.T) {
|
|||||||
t.Error("expected", fakeSegmentCount, "segments, got", len(p.Segments))
|
t.Error("expected", fakeSegmentCount, "segments, got", len(p.Segments))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClip(t *testing.T) {
|
||||||
|
segmentDuration := data.GetStreamLatencyLevel().SecondsPerSegment
|
||||||
|
playlist := NewPlaylistGenerator()
|
||||||
|
clipId, _, err := AddClipForStream(fakeStreamId, "test clip", fakeClipper, float32(fakeClipStartTime), float32(fakeClipEndTime))
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
clips, err := GetAllClips()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(clips) != 1 {
|
||||||
|
t.Error("expected 1 clip, got", len(clips))
|
||||||
|
}
|
||||||
|
|
||||||
|
clip := clips[0]
|
||||||
|
|
||||||
|
if clip.ID != clipId {
|
||||||
|
t.Error("expected clip id", clipId, "got", clip.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if clip.Manifest != fmt.Sprintf("/clip/%s", clipId) {
|
||||||
|
t.Error("expected manifest id", fmt.Sprintf("/clip/%s", clipId), "got", clip.Manifest)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedStartTime := float32(utils.RoundDownToNearest(float32(fakeClipStartTime), segmentDuration))
|
||||||
|
if clip.RelativeStartTime != expectedStartTime {
|
||||||
|
t.Error("expected clip start time", fakeClipStartTime, "got", clip.RelativeStartTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedEndTime := float32(utils.RoundUpToNearest(float32(fakeClipEndTime), segmentDuration))
|
||||||
|
if clip.RelativeEndTime != expectedEndTime {
|
||||||
|
t.Error("expected clip end time", fakeClipEndTime, "got", clip.RelativeEndTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedDuration := expectedEndTime - expectedStartTime
|
||||||
|
if float32(clip.DurationSeconds) != expectedDuration {
|
||||||
|
t.Error("expected clip duration", expectedDuration, "got", clip.DurationSeconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
p, err := playlist.GenerateMediaPlaylistForClipAndConfiguration(clipId, fakeConfigId)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if p == nil {
|
||||||
|
t.Error("expected playlist")
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedSegmentCount := 3
|
||||||
|
if len(p.Segments) != expectedSegmentCount {
|
||||||
|
t.Error("expected", expectedSegmentCount, "segments, got", len(p.Segments))
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.TargetDuration != float64(fakeSegmentDuration) {
|
||||||
|
t.Error("expected target duration of", fakeSegmentDuration, "got", p.TargetDuration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user