Playlist-level retry configuration
This commit is contained in:
@@ -91,6 +91,41 @@ func TestDecodePlaylistFileAllowsEmptyPlaylist(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodePlaylistFileRetry(t *testing.T) {
|
||||
input := `{
|
||||
"retry": {
|
||||
"max_attempts": 3,
|
||||
"initial_delay": "250ms",
|
||||
"max_delay": "2s"
|
||||
},
|
||||
"entries": []
|
||||
}`
|
||||
got, err := decodePlaylistFile(strings.NewReader(input))
|
||||
if err != nil {
|
||||
t.Fatalf("decodePlaylistFile() error = %v", err)
|
||||
}
|
||||
if got.Retry == nil {
|
||||
t.Fatal("decodePlaylistFile() retry = nil")
|
||||
}
|
||||
want := playback.RetryPolicy{
|
||||
MaxAttempts: 3, InitialDelay: 250 * time.Millisecond, MaxDelay: 2 * time.Second,
|
||||
}
|
||||
if *got.Retry != want {
|
||||
t.Fatalf("retry = %#v, want %#v", *got.Retry, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodePlaylistFileRetryDefaults(t *testing.T) {
|
||||
got, err := decodePlaylistFile(strings.NewReader(`{"retry":{},"entries":[]}`))
|
||||
if err != nil {
|
||||
t.Fatalf("decodePlaylistFile() error = %v", err)
|
||||
}
|
||||
if got.Retry == nil || got.Retry.MaxAttempts != 0 ||
|
||||
got.Retry.InitialDelay != initialRetryDelay || got.Retry.MaxDelay != maxRetryDelay {
|
||||
t.Fatalf("retry = %#v", got.Retry)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodePlaylistFileRejectsInvalidInput(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -103,6 +138,10 @@ func TestDecodePlaylistFileRejectsInvalidInput(t *testing.T) {
|
||||
{name: "unknown field", input: `{"unknown": true}`, wantText: "unknown field"},
|
||||
{name: "multiple roots", input: `{"entries": []} {"entries": []}`, wantText: "multiple root values"},
|
||||
{name: "invalid failure policy", input: `{"on_failure":"skip","entries":[]}`, wantErr: playback.ErrPlaylistFailurePolicy},
|
||||
{name: "negative retry attempts", input: `{"retry":{"max_attempts":-1},"entries":[]}`, wantErr: playback.ErrInvalidMaxAttempts},
|
||||
{name: "invalid initial delay", input: `{"retry":{"initial_delay":"soon"},"entries":[]}`, wantText: "retry initial_delay"},
|
||||
{name: "invalid maximum delay", input: `{"retry":{"max_delay":"later"},"entries":[]}`, wantText: "retry max_delay"},
|
||||
{name: "invalid retry range", input: `{"retry":{"initial_delay":"2s","max_delay":"1s"},"entries":[]}`, wantErr: playback.ErrInvalidRetryRange},
|
||||
{
|
||||
name: "invalid duration",
|
||||
input: `{"entries":[{"video":{"domain":"/video","uuid":"video"},"duration":"later"}]}`,
|
||||
|
||||
Reference in New Issue
Block a user