Skip to content

Commit f0276f1

Browse files
committed
refactor(store): move create_n0_bao test util into util::tests::create_n0_bao
1 parent 9a9dc2b commit f0276f1

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

src/api/blobs/reader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,11 @@ mod tests {
225225
protocol::ChunkRangesExt,
226226
store::{
227227
fs::{
228-
tests::{create_n0_bao, test_data, INTERESTING_SIZES},
228+
tests::{test_data, INTERESTING_SIZES},
229229
FsStore,
230230
},
231231
mem::MemStore,
232+
util::tests::create_n0_bao,
232233
},
233234
};
234235

src/api/remote.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,10 +1073,11 @@ mod tests {
10731073
protocol::{ChunkRangesExt, ChunkRangesSeq, GetRequest},
10741074
store::{
10751075
fs::{
1076-
tests::{create_n0_bao, test_data, INTERESTING_SIZES},
1076+
tests::{test_data, INTERESTING_SIZES},
10771077
FsStore,
10781078
},
10791079
mem::MemStore,
1080+
util::tests::create_n0_bao,
10801081
},
10811082
tests::{add_test_hash_seq, add_test_hash_seq_incomplete},
10821083
};

src/store/fs.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,10 +1497,7 @@ pub mod tests {
14971497
use core::panic;
14981498
use std::collections::{HashMap, HashSet};
14991499

1500-
use bao_tree::{
1501-
io::{outboard::PreOrderMemOutboard, round_up_to_chunks_groups},
1502-
ChunkRanges,
1503-
};
1500+
use bao_tree::{io::round_up_to_chunks_groups, ChunkRanges};
15041501
use n0_future::{stream, Stream, StreamExt};
15051502
use testresult::TestResult;
15061503
use walkdir::WalkDir;
@@ -1509,7 +1506,7 @@ pub mod tests {
15091506
use crate::{
15101507
api::blobs::Bitfield,
15111508
store::{
1512-
util::{read_checksummed, SliceInfoExt, Tag},
1509+
util::{read_checksummed, tests::create_n0_bao, SliceInfoExt, Tag},
15131510
IROH_BLOCK_SIZE,
15141511
},
15151512
};
@@ -1526,17 +1523,6 @@ pub mod tests {
15261523
1024 * 1024 * 8, // data file, outboard file
15271524
];
15281525

1529-
/// Create n0 flavoured bao. Note that this can be used to request ranges below a chunk group size,
1530-
/// which can not be exported via bao because we don't store hashes below the chunk group level.
1531-
pub fn create_n0_bao(data: &[u8], ranges: &ChunkRanges) -> anyhow::Result<(Hash, Vec<u8>)> {
1532-
let outboard = PreOrderMemOutboard::create(data, IROH_BLOCK_SIZE);
1533-
let mut encoded = Vec::new();
1534-
let size = data.len() as u64;
1535-
encoded.extend_from_slice(&size.to_le_bytes());
1536-
bao_tree::io::sync::encode_ranges_validated(data, &outboard, ranges, &mut encoded)?;
1537-
Ok((outboard.root.into(), encoded))
1538-
}
1539-
15401526
pub fn round_up_request(size: u64, ranges: &ChunkRanges) -> ChunkRanges {
15411527
let last_chunk = ChunkNum::chunks(size);
15421528
let data_range = ChunkRanges::from(..last_chunk);

src/store/gc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ mod tests {
253253
use crate::{
254254
api::{blobs::AddBytesOptions, ExportBaoError, RequestError, Store},
255255
hashseq::HashSeq,
256-
store::fs::{options::PathOptions, tests::create_n0_bao},
256+
store::{fs::options::PathOptions, util::tests::create_n0_bao},
257257
BlobFormat,
258258
};
259259

src/store/util.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,21 @@ impl bao_tree::io::mixed::Sender for BaoTreeSender {
404404
self.0.send(item).await
405405
}
406406
}
407+
408+
#[cfg(test)]
409+
pub mod tests {
410+
use crate::hash::Hash;
411+
use crate::store::IROH_BLOCK_SIZE;
412+
use bao_tree::{io::outboard::PreOrderMemOutboard, ChunkRanges};
413+
414+
/// Create n0 flavoured bao. Note that this can be used to request ranges below a chunk group size,
415+
/// which can not be exported via bao because we don't store hashes below the chunk group level.
416+
pub fn create_n0_bao(data: &[u8], ranges: &ChunkRanges) -> anyhow::Result<(Hash, Vec<u8>)> {
417+
let outboard = PreOrderMemOutboard::create(data, IROH_BLOCK_SIZE);
418+
let mut encoded = Vec::new();
419+
let size = data.len() as u64;
420+
encoded.extend_from_slice(&size.to_le_bytes());
421+
bao_tree::io::sync::encode_ranges_validated(data, &outboard, ranges, &mut encoded)?;
422+
Ok((outboard.root.into(), encoded))
423+
}
424+
}

src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ use crate::{
1919
provider::events::{AbortReason, EventMask, EventSender, ProviderMessage, RequestUpdate},
2020
store::{
2121
fs::{
22-
tests::{create_n0_bao, test_data, INTERESTING_SIZES},
22+
tests::{test_data, INTERESTING_SIZES},
2323
FsStore,
2424
},
2525
mem::MemStore,
26-
util::observer::Combine,
26+
util::{observer::Combine, tests::create_n0_bao},
2727
},
2828
util::sink::Drain,
2929
BlobFormat, Hash, HashAndFormat,

0 commit comments

Comments
 (0)