package playback import ( "errors" "testing" "time" ) func TestSessionConfigValidate(t *testing.T) { validRetry := RetryPolicy{ MaxAttempts: 5, InitialDelay: 500 * time.Millisecond, MaxDelay: 10 * time.Second, } tests := []struct { name string config SessionConfig wantErr error }{ { name: "audio and video in different domains", config: SessionConfig{ Video: FeedConfig{ Domain: "/dev/shm/mxl-video", UUID: "video-uuid", Active: true, }, Audio: FeedConfig{ Domain: "/dev/shm/mxl-audio", UUID: "audio-uuid", Active: true, }, SyncRequested: true, Retry: validRetry, }, wantErr: nil, }, { name: "audio and video in same domain", config: SessionConfig{ Video: FeedConfig{ Domain: "/dev/shm/mxl", UUID: "video-uuid", Active: true, }, Audio: FeedConfig{ Domain: "/dev/shm/mxl", UUID: "audio-uuid", Active: true, }, SyncRequested: true, Retry: validRetry, }, wantErr: nil, }, { name: "video only", config: SessionConfig{ Video: FeedConfig{ Domain: "/dev/shm/mxl", UUID: "video-uuid", Active: true, }, Retry: validRetry, }, wantErr: nil, }, { name: "audio only", config: SessionConfig{ Audio: FeedConfig{ Domain: "/dev/shm/mxl", UUID: "audio-uuid", Active: true, }, Retry: validRetry, }, wantErr: nil, }, { name: "video UUID without domain", config: SessionConfig{ Video: FeedConfig{ UUID: "video-uuid", Active: true, }, Retry: validRetry, }, wantErr: ErrFeedDomainRequired, }, { name: "audio without domain", config: SessionConfig{ Audio: FeedConfig{ Domain: "", UUID: "audio-uuid", Active: true, }, SyncRequested: true, Retry: validRetry, }, wantErr: ErrFeedDomainRequired, }, { name: "sync with only one feed", config: SessionConfig{ Video: FeedConfig{ Domain: "/dev/shm/mxl-video", UUID: "video-uuid", Active: true, }, SyncRequested: true, Retry: validRetry, }, wantErr: nil, }, { name: "empty player with valid retry policy", config: SessionConfig{ Retry: validRetry, }, wantErr: nil, }, { name: "negative MaxAttempts", config: SessionConfig{ Retry: RetryPolicy{ MaxAttempts: -100, InitialDelay: 500 * time.Millisecond, MaxDelay: 10 * time.Second, }, }, wantErr: ErrInvalidMaxAttempts, }, { name: "zero InitialDelay", config: SessionConfig{ Retry: RetryPolicy{ MaxAttempts: 0, InitialDelay: 0, MaxDelay: 10 * time.Second, }, }, wantErr: ErrInvalidRetryDelay, }, { name: "zero MaxDelay", config: SessionConfig{ Retry: RetryPolicy{ MaxAttempts: 0, InitialDelay: 500 * time.Millisecond, MaxDelay: 0, }, }, wantErr: ErrInvalidRetryDelay, }, { name: "MaxDelay smaller than InitialDelay", config: SessionConfig{ Retry: RetryPolicy{ MaxAttempts: 0, InitialDelay: 500 * time.Millisecond, MaxDelay: 200 * time.Millisecond, }, }, wantErr: ErrInvalidRetryRange, }, { name: "configured video is stopped", config: SessionConfig{ Video: FeedConfig{ Domain: "/dev/shm/mxl-video", UUID: "video-uuid", Active: false, }, Retry: validRetry, }, wantErr: nil, }, { name: "active video without UUID", config: SessionConfig{ Video: FeedConfig{ Domain: "/dev/shm/mxl-video", Active: true, }, Retry: validRetry, }, wantErr: ErrActiveFeedNotConfigured, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { err := tt.config.Validate() if tt.wantErr == nil { if err != nil { t.Fatalf("Validate() returned unexpected error: %v", err) } return } if !errors.Is(err, tt.wantErr) { t.Fatalf( "Validate() error = %v, want error matching %v", err, tt.wantErr, ) } }) } }