Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
it was not properly handling empty slices
  • Loading branch information
rklaehn committed Feb 12, 2024
1 parent 4f9164d commit 5b08d3d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tokio-util = { version = "0.7", default-features = false, optional = true }
x-http = ["reqwest"]
tokio-io = ["tokio", "smallvec"]
stats = []
default = ["tokio-io", "x-http"]
default = ["tokio-io"]

[package.metadata.docs.rs]
features = ["x-http", "tokio-io", "stats"]
Expand Down
14 changes: 11 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ mod tests {
use super::*;
use bytes::BytesMut;
use proptest::prelude::*;
use std::io;
use std::{fmt::Debug, io};

#[cfg(feature = "tokio-io")]
use std::io::Write;
Expand Down Expand Up @@ -393,9 +393,16 @@ mod tests {
if let Some(range_header) = req.headers().get("Range") {
if let Ok(range) = parse_range_header(range_header.to_str().unwrap()) {
// Extract the requested range from the data
let start = range.start;
let start = range.start.min(data.len());
let end = range.end.min(data.len());
let sliced_data = &data[start..end];
if start == end {
return Response::builder()
.header("Content-Type", "application/octet-stream")
.status(StatusCode::NO_CONTENT)
.body(Body::from(vec![]))
.unwrap();
}

// Create a partial response with the sliced data
return Response::builder()
Expand Down Expand Up @@ -653,7 +660,7 @@ mod tests {
io::Result::Ok(())
}

async fn read_op_test<R: AsyncSliceReader>(
async fn read_op_test<R: AsyncSliceReader + Debug>(
ops: Vec<ReadOp>,
mut file: R,
actual: &[u8],
Expand All @@ -662,6 +669,7 @@ mod tests {
for op in ops {
match op {
ReadOp::ReadAt(offset, len) => {
println!("{:?} {} {}", file, offset, len);
let data = AsyncSliceReader::read_at(&mut file, offset, len).await?;
assert_eq!(&data, &actual[limited_range(offset, len, actual.len())]);
current = offset.checked_add(len as u64).unwrap();
Expand Down

0 comments on commit 5b08d3d

Please sign in to comment.