208 lines
5.3 KiB
Go
208 lines
5.3 KiB
Go
package playback
|
|
|
|
import "testing"
|
|
|
|
func TestIsSessionPlaying(t *testing.T) {
|
|
const generation = 4
|
|
playing := func(unit Unit) Status {
|
|
return Status{Unit: unit, State: StatePlaying, Generation: generation}
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
session SessionSnapshot
|
|
statuses PlaybackStatusSnapshot
|
|
want bool
|
|
}{
|
|
{
|
|
name: "video only playing",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{
|
|
Topology: TopologyIndependent,
|
|
Video: FeedConfig{UUID: "video", Active: true},
|
|
},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{
|
|
Generation: generation,
|
|
Video: playing(UnitVideo),
|
|
HasVideo: true,
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "audio only playing",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{
|
|
Topology: TopologyIndependent,
|
|
Audio: FeedConfig{UUID: "audio", Active: true},
|
|
},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{
|
|
Generation: generation,
|
|
Audio: playing(UnitAudio),
|
|
HasAudio: true,
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "both independent feeds playing",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{
|
|
Topology: TopologyIndependent,
|
|
Video: FeedConfig{UUID: "video", Active: true},
|
|
Audio: FeedConfig{UUID: "audio", Active: true},
|
|
},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{
|
|
Generation: generation,
|
|
Video: playing(UnitVideo),
|
|
HasVideo: true,
|
|
Audio: playing(UnitAudio),
|
|
HasAudio: true,
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "only video of independent pair playing",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{
|
|
Topology: TopologyIndependent,
|
|
Video: FeedConfig{UUID: "video", Active: true},
|
|
Audio: FeedConfig{UUID: "audio", Active: true},
|
|
},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{
|
|
Generation: generation,
|
|
Video: playing(UnitVideo),
|
|
HasVideo: true,
|
|
Audio: Status{Unit: UnitAudio, State: StateConnecting, Generation: generation},
|
|
HasAudio: true,
|
|
},
|
|
},
|
|
{
|
|
name: "synchronized unit playing",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{Topology: TopologySynchronized},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{
|
|
Generation: generation,
|
|
Sync: playing(UnitSync),
|
|
HasSync: true,
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "sync ignores independent playing statuses",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{Topology: TopologySynchronized},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{
|
|
Generation: generation,
|
|
Video: playing(UnitVideo),
|
|
HasVideo: true,
|
|
Audio: playing(UnitAudio),
|
|
HasAudio: true,
|
|
},
|
|
},
|
|
{
|
|
name: "reconnecting is not playing",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{
|
|
Topology: TopologyIndependent,
|
|
Video: FeedConfig{UUID: "video", Active: true},
|
|
},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{
|
|
Generation: generation,
|
|
Video: Status{Unit: UnitVideo, State: StateReconnecting, Generation: generation},
|
|
HasVideo: true,
|
|
},
|
|
},
|
|
{
|
|
name: "missing status",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{
|
|
Topology: TopologyIndependent,
|
|
Video: FeedConfig{UUID: "video", Active: true},
|
|
},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{Generation: generation},
|
|
},
|
|
{
|
|
name: "older status snapshot",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{Topology: TopologySynchronized},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{
|
|
Generation: generation - 1,
|
|
Sync: Status{Unit: UnitSync, State: StatePlaying, Generation: generation - 1},
|
|
HasSync: true,
|
|
},
|
|
},
|
|
{
|
|
name: "newer status snapshot",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{Topology: TopologySynchronized},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{
|
|
Generation: generation + 1,
|
|
Sync: Status{Unit: UnitSync, State: StatePlaying, Generation: generation + 1},
|
|
HasSync: true,
|
|
},
|
|
},
|
|
{
|
|
name: "individual status has wrong generation",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{Topology: TopologySynchronized},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{
|
|
Generation: generation,
|
|
Sync: Status{Unit: UnitSync, State: StatePlaying, Generation: generation - 1},
|
|
HasSync: true,
|
|
},
|
|
},
|
|
{
|
|
name: "idle",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{Topology: TopologyIdle},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{Generation: generation},
|
|
},
|
|
{
|
|
name: "unknown topology",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{Topology: SessionTopology(255)},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{Generation: generation},
|
|
},
|
|
{
|
|
name: "independent without active feeds",
|
|
session: SessionSnapshot{
|
|
Generation: generation,
|
|
Plan: SessionPlan{Topology: TopologyIndependent},
|
|
},
|
|
statuses: PlaybackStatusSnapshot{Generation: generation},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
if got := IsSessionPlaying(test.session, test.statuses); got != test.want {
|
|
t.Fatalf("IsSessionPlaying() = %v, want %v", got, test.want)
|
|
}
|
|
})
|
|
}
|
|
}
|