package mxladapter import ( "context" "errors" "fmt" "testing" "mxl-player/internal/source" ) func TestShouldRetrySourceError(t *testing.T) { baseErr := errors.New("source failed") classified := func(kind source.ErrorKind) error { return &source.SourceError{ Op: "read media", Kind: kind, Err: baseErr, } } tests := []struct { name string err error want bool }{ { name: "temporary source error is retryable", err: classified(source.ErrorKindTemporary), want: true, }, { name: "unavailable source is retryable", err: classified(source.ErrorKindUnavailable), want: true, }, { name: "invalid configuration is not retryable", err: classified(source.ErrorKindInvalidConfig), want: false, }, { name: "ordinary unknown error is retryable", err: baseErr, want: true, }, { name: "wrapped invalid configuration is not retryable", err: fmt.Errorf( "worker failed: %w", classified(source.ErrorKindInvalidConfig), ), want: false, }, { name: "context cancellation is not retryable", err: context.Canceled, want: false, }, { name: "wrapped context cancellation is not retryable", err: fmt.Errorf("worker stopped: %w", context.Canceled), want: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := ShouldRetry(tt.err); got != tt.want { t.Errorf("ShouldRetry() = %t, want %t", got, tt.want) } }) } }