internal/player_subtitle_test.go

31 lines · 755 bytes

1 symbol in this file
 1package internal
 2
 3import (
 4	"errors"
 5	"testing"
 6	"time"
 7)
 8
 9func TestWaitForMPVFileReadyRetriesUntilPropertiesExist(t *testing.T) {
10	pathCalls := 0
11	sender := func(_ string, command []interface{}) (interface{}, error) {
12		switch command[1] {
13		case "path":
14			pathCalls++
15			if pathCalls < 3 {
16				return nil, errors.New("property unavailable")
17			}
18			return "https://cdn.example/episode.m3u8", nil
19		case "duration":
20			return float64(1440), nil
21		default:
22			return nil, errors.New("unexpected command")
23		}
24	}
25	if err := waitForMPVFileReadyWith(sender, "socket", "https://cdn.example/episode.m3u8", 100*time.Millisecond, time.Millisecond); err != nil {
26		t.Fatal(err)
27	}
28	if pathCalls != 3 {
29		t.Fatalf("path queried %d times, want 3", pathCalls)
30	}
31}