internal/player_playback_test.go

45 lines · 1421 bytes

3 symbols in this file
 1package internal
 2
 3import (
 4	"errors"
 5	"testing"
 6	"time"
 7)
 8
 9func TestWaitForMPVPlaybackStartSkipsNonIPCPlayers(t *testing.T) {
10	timeout := MpvPlaybackStartTimeoutDuration(nil)
11	if !WaitForMPVPlaybackStart("android-intent", timeout) {
12		t.Fatal("expected android-intent playback wait to succeed immediately")
13	}
14	if !WaitForMPVPlaybackStart("", timeout) {
15		t.Fatal("expected empty socket playback wait to succeed immediately")
16	}
17}
18
19func TestMpvPlaybackStartTimeoutDurationUsesConfig(t *testing.T) {
20	config := PopulateConfig(map[string]string{
21		"MpvPlaybackStartTimeout": "45",
22	})
23	if got := MpvPlaybackStartTimeoutDuration(&config); got != 45*time.Second {
24		t.Fatalf("expected 45s timeout, got %s", got)
25	}
26}
27
28func TestIsMPVConnectionGoneError(t *testing.T) {
29	for _, message := range []string{
30		"dial unix /tmp/curd: connect: connection refused",
31		"dial unix /tmp/curd: connect: no such file or directory",
32		"open \\\\.\\pipe\\curd: The system cannot find the file specified.",
33		"read \\\\.\\pipe\\curd: The pipe has been ended.",
34		"write \\\\.\\pipe\\curd: The pipe is being closed.",
35		"read \\\\.\\pipe\\curd: No process is on the other end of the pipe.",
36	} {
37		if !isMPVConnectionGoneError(errors.New(message)) {
38			t.Fatalf("expected gone error for %q", message)
39		}
40	}
41
42	if isMPVConnectionGoneError(errors.New("i/o timeout")) {
43		t.Fatal("did not expect timeout to be treated as closed connection")
44	}
45}