test: add unit tests for calculate_piece_range #907
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request includes several changes aimed at refactoring the code for calculating piece ranges and improving the test coverage. The main changes involve extracting the
calculate_piece_range
function into a standalone function and updating the related code to use this new function.Refactoring and code improvement:
dragonfly-client-storage/src/content.rs
: Extracted the logic for calculating the target offset and length based on the range into a new functioncalculate_piece_range
. This function is now called in theimpl Content
block instead of the inline logic. [1] [2] [3]dragonfly-client/src/proxy/cache.rs
: Similarly, extracted the logic for calculating the target offset and length into thecalculate_piece_range
function and updated theimpl Cache
block to use this function. [1] [2] [3]Test coverage:
calculate_piece_range
function in bothdragonfly-client-storage
anddragonfly-client
to ensure the correctness of the calculations. [1] [2]Dependency update:
dragonfly-client-storage/Cargo.toml
: Addedtempfile.workspace = true
to thedev-dependencies
section to support the new tests.Minor improvement:
dragonfly-client/src/proxy/mod.rs
: Added a comment to clarify the logic for adding a piece to the cache when the piece reader reaches the end.Related Issue
Motivation and Context
Screenshots (if appropriate)