Skip to content

Conversation

@spiegel-im-spiegel
Copy link
Member

  • Updated DownloadImage to use a package-level createFile helper for file creation, allowing for better testing and error simulation.
  • Enhanced error handling in DownloadImage to cover scenarios like directory creation failures and read errors during HTTP response processing.
  • Refactored DownloadThumbnail to utilize the createFile helper and improved error handling for file creation and image processing.
  • Added comprehensive unit tests for DownloadImage and DownloadThumbnail to cover various edge cases, including error scenarios and temporary file handling.
  • Improved documentation for both methods to clarify behavior, parameters, and error handling.

…or handling and file management

- Updated DownloadImage to use a package-level createFile helper for file creation, allowing for better testing and error simulation.
- Enhanced error handling in DownloadImage to cover scenarios like directory creation failures and read errors during HTTP response processing.
- Refactored DownloadThumbnail to utilize the createFile helper and improved error handling for file creation and image processing.
- Added comprehensive unit tests for DownloadImage and DownloadThumbnail to cover various edge cases, including error scenarios and temporary file handling.
- Improved documentation for both methods to clarify behavior, parameters, and error handling.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the DownloadImage and DownloadThumbnail methods to improve testability and error handling. The main changes introduce package-level function variables (createFile, decodeImage, outputImage) that tests can override to simulate failure scenarios. The PR adds comprehensive test coverage for edge cases including file creation failures, read errors, and encoding issues. Documentation has been enhanced with detailed API notes and test examples showing how to use the new test hooks.

Key changes:

  • Introduced testable dependency injection via package-level function variables for file creation, image decoding, and encoding
  • Removed hardcoded 15-second HTTP timeout from DownloadImage (now relies on context for cancellation)
  • Unified file creation and closing logic for both temporary and permanent files in both methods
  • Added 20+ new test cases covering error paths and edge cases

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
webinfo.go Refactored DownloadImage and DownloadThumbnail to use createFile, decodeImage, and outputImage function variables; removed HTTP timeout; simplified defer/close logic
webinfo_test.go Added extensive test coverage including helper types (errReader, roundTripperFunc, failingBody, zeroImg) and 20+ new test cases for error scenarios
fetch_test.go Added tests for custom User-Agent and body close errors
README.md Enhanced documentation with API notes section explaining test hooks and added comprehensive test examples
.github/copilot-instructions.md Updated with detailed image download/thumbnail notes and clarifications on I/O patterns
Taskfile.yml Added coverage profile generation and reporting to the test task
sample/sample1.go New example demonstrating basic Fetch usage with context timeout
sample/sample2.go New example demonstrating DownloadThumbnail usage

@spiegel-im-spiegel
Copy link
Member Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Nov 28, 2025

@spiegel-im-spiegel I've opened a new pull request, #3, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Copilot AI and others added 2 commits November 28, 2025 05:45
Fix review comments: remove io.NopCloser wrapper, add HTTP timeout, fix typos
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

@spiegel-im-spiegel spiegel-im-spiegel marked this pull request as draft November 28, 2025 06:16
@spiegel-im-spiegel spiegel-im-spiegel marked this pull request as ready for review November 28, 2025 06:16
@spiegel-im-spiegel spiegel-im-spiegel marked this pull request as draft November 28, 2025 06:19
@spiegel-im-spiegel spiegel-im-spiegel marked this pull request as ready for review November 28, 2025 06:23
@spiegel-im-spiegel spiegel-im-spiegel merged commit 3845ddc into main Nov 28, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants