test(download): add unit/integration tests for parallel download engine #139

Closed
opened 2026-07-13 18:08:00 +00:00 by the.auditor · 1 comment
Owner

internal/downloader/download.go has no tests. 207 lines of core download logic — the heart of pget — with zero test coverage.

Critical paths to cover:

  • Download() — HTTP with ranges, HTTP without ranges, FTP with REST, FTP without REST
  • runWorker — successful chunk, retry on failure, context cancellation during backoff
  • downloadChunkHTTP — 206 response, 200 response, error status, network failure
  • downloadChunkFTP — successful RETR, connection failure
  • writeAtSeeker — WriteAt positioning
  • preallocFile — normal creation, truncate failure
  • retryBackoff — backoff timing for each attempt
  • isFTPURL — ftp://, ftps://, http://, https://
  • First-chunk-failure aborts remaining workers cleanly (no goroutine leak)
  • Single-threaded fallback with unknown file size

Use httptest.NewServer with range-aware handler for HTTP tests.

Discovered during review of PR #137.

`internal/downloader/download.go` has no tests. 207 lines of core download logic — the heart of pget — with zero test coverage. Critical paths to cover: - `Download()` — HTTP with ranges, HTTP without ranges, FTP with REST, FTP without REST - `runWorker` — successful chunk, retry on failure, context cancellation during backoff - `downloadChunkHTTP` — 206 response, 200 response, error status, network failure - `downloadChunkFTP` — successful RETR, connection failure - `writeAtSeeker` — WriteAt positioning - `preallocFile` — normal creation, truncate failure - `retryBackoff` — backoff timing for each attempt - `isFTPURL` — ftp://, ftps://, http://, https:// - First-chunk-failure aborts remaining workers cleanly (no goroutine leak) - Single-threaded fallback with unknown file size Use `httptest.NewServer` with range-aware handler for HTTP tests. Discovered during review of PR #137.
Owner

Closing — handled in PR #161. download_test.go has 16 tests covering parallel download, range, no-range, resume, retries, checksum, rate limiting, and context cancellation.

Closing — handled in PR #161. download_test.go has 16 tests covering parallel download, range, no-range, resume, retries, checksum, rate limiting, and context cancellation.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/pget#139
No description provided.