Files
wehub-resource-sync ead81af521
Deploy to GitHub Pages / deploy (push) Failing after 0s
CI / go (push) Has been cancelled
CI / build (darwin, macos-14) (push) Has been cancelled
CI / build (windows, windows-2025) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:13 +08:00

79 lines
1.6 KiB
Go

package model
import (
"testing"
"time"
"github.com/bjarneo/cliamp/playlist"
)
func TestShouldReconnectOnUnpause(t *testing.T) {
tests := []struct {
name string
track playlist.Track
idx int
pause time.Duration
want bool
}{
{
name: "live http stream reconnects",
track: playlist.Track{
Path: "https://radio.example.com/stream",
Stream: true,
Realtime: true,
},
idx: 0,
want: true,
},
{
name: "short-paused yt-dlp stream does not reconnect",
track: playlist.Track{
Path: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
Stream: true,
},
idx: 0,
pause: ytdlReconnectPauseThreshold - time.Second,
want: false,
},
{
name: "long-paused yt-dlp stream reconnects",
track: playlist.Track{
Path: "https://music.youtube.com/watch?v=dQw4w9WgXcQ",
Stream: true,
},
idx: 0,
pause: ytdlReconnectPauseThreshold,
want: true,
},
{
name: "invalid current index does not reconnect",
track: playlist.Track{
Path: "https://radio.example.com/stream",
Stream: true,
Realtime: true,
},
idx: -1,
want: false,
},
{
name: "known duration live stream still reconnects",
track: playlist.Track{
Path: "https://radio.example.com/show.mp3",
Stream: true,
Realtime: true,
DurationSecs: 120,
},
idx: 0,
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := shouldReconnectOnUnpause(tt.track, tt.idx, tt.pause); got != tt.want {
t.Fatalf("shouldReconnectOnUnpause(...) = %v, want %v", got, tt.want)
}
})
}
}