diff options
author | Florian Klink <flokli@flokli.de> | 2023-02-27T07·59+0100 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2023-03-10T10·58+0000 |
commit | 28a862976bd43912e0e5dc16e8919590c36f4cf0 (patch) | |
tree | f6e6fb7eac5145c9519ff8399a14ab1733a75c66 /tvix/store/src/blobreader.rs | |
parent | 0baaabc43e3027b1676874c536d5ade27abe14b8 (diff) |
refactor(tvix/store/tests): move gen_*_service() into helper r/5928
This allows hiding to tests what exact implementation we're using, when testing things that do something with a store, but don't care what's used for underlying storage. Change-Id: I7cdf60fd73c25d5050159cb31ec177db2bc2a7f1 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8155 Tested-by: BuildkiteCI Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Diffstat (limited to 'tvix/store/src/blobreader.rs')
-rw-r--r-- | tvix/store/src/blobreader.rs | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/tvix/store/src/blobreader.rs b/tvix/store/src/blobreader.rs index 47ddfae03c7b..5fb26228be65 100644 --- a/tvix/store/src/blobreader.rs +++ b/tvix/store/src/blobreader.rs @@ -133,13 +133,12 @@ impl<CS: ChunkService> std::io::Read for BlobReader<'_, CS> { mod tests { use super::BlobReader; use crate::chunkservice::ChunkService; - use crate::chunkservice::SledChunkService; use crate::proto; + use crate::tests::utils::gen_chunk_service; use lazy_static::lazy_static; use std::io::Cursor; use std::io::Read; use std::io::Write; - use std::path::PathBuf; use tempfile::TempDir; lazy_static! { @@ -152,15 +151,11 @@ mod tests { static ref DUMMY_DATA_2: Vec<u8> = vec![0x04, 0x05]; } - fn gen_chunk_service(p: PathBuf) -> impl ChunkService { - SledChunkService::new(p.join("chunks")).unwrap() - } - #[test] /// reading from a blobmeta with zero chunks should produce zero bytes. fn empty_blobmeta() -> anyhow::Result<()> { let tmpdir = TempDir::new()?; - let chunk_service = gen_chunk_service(tmpdir.path().to_path_buf()); + let chunk_service = gen_chunk_service(tmpdir.path()); let blobmeta = proto::BlobMeta { chunks: vec![], @@ -181,7 +176,7 @@ mod tests { /// trying to read something where the chunk doesn't exist should fail fn missing_chunk_fail() -> anyhow::Result<()> { let tmpdir = TempDir::new()?; - let chunk_service = gen_chunk_service(tmpdir.path().to_path_buf()); + let chunk_service = gen_chunk_service(tmpdir.path()); let blobmeta = proto::BlobMeta { chunks: vec![proto::blob_meta::ChunkMeta { @@ -205,7 +200,7 @@ mod tests { /// read something containing the single (empty) chunk fn empty_chunk() -> anyhow::Result<()> { let tmpdir = TempDir::new()?; - let chunk_service = gen_chunk_service(tmpdir.path().to_path_buf()); + let chunk_service = gen_chunk_service(tmpdir.path()); // insert a single chunk let dgst = chunk_service.put(vec![]).expect("must succeed"); @@ -236,7 +231,7 @@ mod tests { #[test] fn single_chunk() -> anyhow::Result<()> { let tmpdir = TempDir::new()?; - let chunk_service = gen_chunk_service(tmpdir.path().to_path_buf()); + let chunk_service = gen_chunk_service(tmpdir.path()); // insert a single chunk let dgst = chunk_service @@ -269,7 +264,7 @@ mod tests { #[test] fn wrong_size_fail() -> anyhow::Result<()> { let tmpdir = TempDir::new()?; - let chunk_service = gen_chunk_service(tmpdir.path().to_path_buf()); + let chunk_service = gen_chunk_service(tmpdir.path()); // insert chunks let dgst_1 = chunk_service @@ -300,7 +295,7 @@ mod tests { #[test] fn multiple_chunks() -> anyhow::Result<()> { let tmpdir = TempDir::new()?; - let chunk_service = gen_chunk_service(tmpdir.path().to_path_buf()); + let chunk_service = gen_chunk_service(tmpdir.path()); // insert chunks let dgst_1 = chunk_service |