Files
2026-09-01 18:03:18 +03:00

91 lines
2.1 KiB
Go

package playback
import (
"context"
"errors"
"testing"
"time"
)
func TestGenerationContext(t *testing.T) {
if got := generationFromContext(context.Background()); got != 0 {
t.Fatalf("background generation = %d, want 0", got)
}
ctx := withGeneration(context.Background(), 42)
if got := generationFromContext(ctx); got != 42 {
t.Fatalf("generation = %d, want 42", got)
}
}
func TestStatusPreservesValues(t *testing.T) {
wantErr := errors.New("producer missing")
status := Status{
Unit: UnitVideo,
State: StateReconnecting,
Attempt: 2,
FailedAttempts: 1,
RetryIn: time.Second,
Err: wantErr,
}
if status.Unit != UnitVideo {
t.Errorf("Unit = %v, want %v", status.Unit, UnitVideo)
}
if !errors.Is(status.Err, wantErr) {
t.Errorf("Err = %v, want %v", status.Err, wantErr)
}
if status.State != StateReconnecting {
t.Errorf("State = %v, want %v", status.State, StateReconnecting)
}
if status.Attempt != 2 {
t.Errorf("Attempt = %d, want 2", status.Attempt)
}
if status.FailedAttempts != 1 {
t.Errorf("FailedAttempts = %d, want 1", status.FailedAttempts)
}
if status.RetryIn != time.Second {
t.Errorf("RetryIn = %s, want %s", status.RetryIn, time.Second)
}
}
func TestUnitString(t *testing.T) {
tests := []struct {
unit Unit
want string
}{
{unit: UnitVideo, want: "video"},
{unit: UnitAudio, want: "audio"},
{unit: UnitSync, want: "sync"},
{unit: Unit(255), want: "Unit(255)"},
}
for _, tt := range tests {
if got := tt.unit.String(); got != tt.want {
t.Errorf("Unit(%d).String() = %q, want %q", tt.unit, got, tt.want)
}
}
}
func TestStateString(t *testing.T) {
tests := []struct {
state State
want string
}{
{state: StateIdle, want: "idle"},
{state: StateConnecting, want: "connecting"},
{state: StatePlaying, want: "playing"},
{state: StateReconnecting, want: "reconnecting"},
{state: StateFailed, want: "failed"},
{state: StateStopping, want: "stopping"},
{state: State(255), want: "State(255)"},
}
for _, tt := range tests {
if got := tt.state.String(); got != tt.want {
t.Errorf("State(%d).String() = %q, want %q", tt.state, got, tt.want)
}
}
}