Files
uptodownbot/internal/dl/progress_test.go
db123 cd27b4d28d feat: add thumbnail preview, audio-only detection, /download command, tests, and bugfixes
- Add thumbnail preview with metadata (title, uploader, duration) before download
- Auto-detect audio-only sites (Spotify, SoundCloud, etc.) and skip type selection
- Add /download command for feature parity with UI button
- Fix yt-dlp defer bug: StatusFailed was overwritten to StatusCompleted
- Fix handleURLInput using editText with msgID=0 (now uses sendWithKB)
- Fix filename detection: use job ID prefix for reliable file finding
- Fix double answerCb between handleBackStep and handleDownloadPrompt
- Fix runDownload unused msgID parameter
- Fix context for download goroutine (use context.Background)
- Remove unused startWebhook h parameter
- Remove dead buildToggleKeyboard function
- Add formatBytes, formatDuration, formatLabelForDisplay tests
- Add IsAudioOnlyContent, MediaType.String tests
- Add repo integration tests (users, preferences, quotas, history, delete)
- Add cmd/bot tests (parseAllowedUsers, env helpers)
- Add edge case tests for progress parser
- Add zero/negative safety guard in formatDuration
- Add .gitea, TODO.md, opencode.json to gitignore
2026-06-25 15:07:31 +03:30

122 lines
2.7 KiB
Go

package dl
import (
"math"
"testing"
)
func TestParseProgressLine(t *testing.T) {
tests := []struct {
line string
pct float64
speed string
eta string
hasRes bool
}{
{
line: "[download] 45.2% of 123.45MiB at 2.34MiB/s ETA 00:45",
pct: 45.2,
speed: "2.34MiB/s",
eta: "00:45",
hasRes: true,
},
{
line: "[download] 10.0% of ~500.00MiB at 1.50MiB/s ETA 05:30",
pct: 10.0,
speed: "1.50MiB/s",
eta: "05:30",
hasRes: true,
},
{
line: "[download] 100.0% of 50.00MiB at 5.00MiB/s ETA 00:00",
pct: 100.0,
speed: "5.00MiB/s",
eta: "00:00",
hasRes: true,
},
{
line: "[youtube] Extracting URL: https://example.com",
hasRes: false,
},
{
line: "",
hasRes: false,
},
{
line: "some random log line",
hasRes: false,
},
{
line: "[download] 0.0% of 1.00GiB at 0.00B/s ETA 00:00",
pct: 0.0,
speed: "0.00B/s",
eta: "00:00",
hasRes: true,
},
{
line: "[download] 0.0% of 1.00KiB at 100.00KiB/s ETA 00:01",
pct: 0.0,
speed: "100.00KiB/s",
eta: "00:01",
hasRes: true,
},
{
line: "[download] 50.5% of 2.00MiB at 500.00KiB/s ETA 00:02",
pct: 50.5,
speed: "500.00KiB/s",
eta: "00:02",
hasRes: true,
},
{
line: "[download] 1.2% of unknown size at 0.00B/s ETA Unknown",
hasRes: false,
},
{
line: "[Merge] Merging video and audio...",
hasRes: false,
},
}
for _, tt := range tests {
got := parseProgressLine(tt.line)
if !tt.hasRes {
if got != nil {
t.Errorf("parseProgressLine(%q) = %+v, want nil", tt.line, got)
}
continue
}
if got == nil {
t.Errorf("parseProgressLine(%q) = nil, want result", tt.line)
continue
}
if math.Abs(got.pct-tt.pct) > 0.01 {
t.Errorf("parseProgressLine(%q).pct = %f, want %f", tt.line, got.pct, tt.pct)
}
if got.speed != tt.speed {
t.Errorf("parseProgressLine(%q).speed = %q, want %q", tt.line, got.speed, tt.speed)
}
if got.eta != tt.eta {
t.Errorf("parseProgressLine(%q).eta = %q, want %q", tt.line, got.eta, tt.eta)
}
}
}
func TestParseProgressLineEdgeCases(t *testing.T) {
tests := []struct {
line string
name string
hasRes bool
}{
{"[download] 0.0% of 1.00GiB at 0.00B/s ETA 00:00", "multiple spaces", true},
{"[download] 100.0% of 1.00GiB at 999.99MiB/s ETA 00:00", "high speed", true},
{"[download] 100.0% of 999.99TiB at 1.00TiB/s ETA 00:00", "large numbers", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := parseProgressLine(tt.line)
if tt.hasRes && got == nil {
t.Errorf("parseProgressLine(%q) = nil, want result", tt.line)
}
})
}
}