package mxladapter import ( "context" "errors" "testing" "mxl-player/internal/playback" "mxl-player/internal/source" ) func TestVideoFactoryOpenVideoCanceled(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() reader, err := (VideoFactory{}).OpenVideo(ctx, playback.FeedConfig{}) if reader != nil { t.Fatal("OpenVideo() reader is not nil after cancellation") } if !errors.Is(err, context.Canceled) { t.Fatalf("OpenVideo() error = %v, want context.Canceled", err) } } func TestVideoFactoryOpenVideoRejectsInvalidConfig(t *testing.T) { tests := []struct { name string config playback.FeedConfig }{ { name: "feed is not configured", config: playback.FeedConfig{}, }, { name: "active feed has no UUID", config: playback.FeedConfig{ Domain: "/dev/shm/mxl", Active: true, }, }, { name: "configured feed has no domain", config: playback.FeedConfig{ UUID: "video-uuid", Active: true, }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { reader, err := (VideoFactory{}).OpenVideo( context.Background(), tt.config, ) if reader != nil { t.Fatal("OpenVideo() reader is not nil for invalid config") } if err == nil { t.Fatal("OpenVideo() error is nil for invalid config") } if got := source.KindOf(err); got != source.ErrorKindInvalidConfig { t.Fatalf( "source.KindOf(OpenVideo()) = %v, want %v", got, source.ErrorKindInvalidConfig, ) } if ShouldRetry(err) { t.Fatal("ShouldRetry(OpenVideo()) = true for invalid config") } }) } }