Files
uptodownbot/internal/dl/ytdlp_test.go
db123 37e7f918d0
All checks were successful
CI / build (push) Successful in 51s
refactor: remove container selection, extract helpers, add logging and tests
- Remove container picker UI, keyboard, settings, and ContainerOptions
  entirely — yt-dlp handles container format automatically
- Remove Container field from DownloadJob struct and related references
- Extract buildFormatList helper to deduplicate format list building
  between handleURLInput and handleBackStep
- Break runDownload into trackDownloadProgress + handleDownloadCompletion
- Add HTTP timeout (30s) to downloadFile helper
- Log applyQuota and AddHistory errors instead of discarding
- Log nil stepState warnings in all handler entry points
- Include job.StderrLog in download failure messages
- Add tests for buildFormatList, findFormatByID, determineMediaType,
  and buildFormatString
- Update README with search, DRM fallback, and quota feature docs
- Remove unused strings import from keyboard.go
2026-06-25 23:41:26 +03:30

74 lines
2.3 KiB
Go

package dl
import (
"testing"
"uptodownBot/internal/domain"
)
func TestFilterFormatsByType(t *testing.T) {
formats := []domain.Format{
{ID: "1", HasVideo: true, HasAudio: false, IsVideoOnly: true, IsAudioOnly: false},
{ID: "2", HasVideo: false, HasAudio: true, IsVideoOnly: false, IsAudioOnly: true},
{ID: "3", HasVideo: true, HasAudio: true, IsVideoOnly: false, IsAudioOnly: false},
{ID: "4", HasVideo: true, HasAudio: false, IsVideoOnly: true, IsAudioOnly: false},
{ID: "5", HasVideo: false, HasAudio: true, IsVideoOnly: false, IsAudioOnly: true},
}
tests := []struct {
mediaType domain.MediaType
wantIDs []string
}{
{domain.MediaTypeAudio, []string{"2", "5"}},
{domain.MediaTypeVideo, []string{"1", "4"}},
{domain.MediaTypeVideoAudio, []string{"3"}},
}
for _, tt := range tests {
got := FilterFormatsByType(formats, tt.mediaType)
if len(got) != len(tt.wantIDs) {
t.Errorf("FilterFormatsByType(%v) = %d results, want %d", tt.mediaType, len(got), len(tt.wantIDs))
continue
}
for i, f := range got {
if f.ID != tt.wantIDs[i] {
t.Errorf("FilterFormatsByType(%v)[%d].ID = %s, want %s", tt.mediaType, i, f.ID, tt.wantIDs[i])
}
}
}
}
func TestDeduplicateResolutions(t *testing.T) {
formats := []domain.Format{
{ID: "1", Resolution: "1920x1080", Height: 1080, IsVideoOnly: true},
{ID: "2", Resolution: "1920x1080", Height: 1080, IsVideoOnly: true},
{ID: "3", Resolution: "1280x720", Height: 720, IsVideoOnly: true},
{ID: "4", Bitrate: "128k", IsAudioOnly: true},
{ID: "5", Bitrate: "128k", IsAudioOnly: true},
}
got := DeduplicateResolutions(formats)
if len(got) != 3 {
t.Errorf("DeduplicateResolutions = %d results, want 3", len(got))
}
}
func TestFormatLabel(t *testing.T) {
tests := []struct {
f domain.Format
want string
}{
{domain.Format{IsAudioOnly: true, Bitrate: "128k"}, "128k"},
{domain.Format{ID: "140", Extension: "m4a", IsAudioOnly: true}, "140 (m4a)"},
{domain.Format{ID: "251", IsAudioOnly: true}, "251"},
{domain.Format{Resolution: "1920x1080", Height: 1080}, "1920x1080"},
{domain.Format{Height: 720}, "720p"},
{domain.Format{ID: "137"}, "137"},
}
for _, tt := range tests {
got := formatLabel(tt.f)
if got != tt.want {
t.Errorf("formatLabel(%+v) = %q, want %q", tt.f, got, tt.want)
}
}
}