diff options
Diffstat (limited to 'tvix/store/src/tests')
-rw-r--r-- | tvix/store/src/tests/import.rs | 56 | ||||
-rw-r--r-- | tvix/store/src/tests/nar_renderer.rs | 51 | ||||
-rw-r--r-- | tvix/store/src/tests/utils.rs | 18 |
3 files changed, 52 insertions, 73 deletions
diff --git a/tvix/store/src/tests/import.rs b/tvix/store/src/tests/import.rs index e8373b614e91..63ca1efa13f3 100644 --- a/tvix/store/src/tests/import.rs +++ b/tvix/store/src/tests/import.rs @@ -12,15 +12,18 @@ use tempfile::TempDir; fn symlink() { let tmpdir = TempDir::new().unwrap(); - let data_dir = tmpdir.path().join("data"); - std::fs::create_dir_all(&data_dir).unwrap(); - std::os::unix::fs::symlink("/nix/store/somewhereelse", data_dir.join("doesntmatter")).unwrap(); + std::fs::create_dir_all(&tmpdir).unwrap(); + std::os::unix::fs::symlink( + "/nix/store/somewhereelse", + tmpdir.path().join("doesntmatter"), + ) + .unwrap(); let root_node = import_path( - &mut gen_blob_service(tmpdir.path()), - &mut gen_chunk_service(tmpdir.path()), - &mut gen_directory_service(tmpdir.path()), - data_dir.join("doesntmatter"), + &mut gen_blob_service(), + &mut gen_chunk_service(), + &mut gen_directory_service(), + tmpdir.path().join("doesntmatter"), ) .expect("must succeed"); @@ -37,17 +40,15 @@ fn symlink() { fn single_file() { let tmpdir = TempDir::new().unwrap(); - let data_dir = tmpdir.path().join("data"); - std::fs::create_dir_all(&data_dir).unwrap(); - std::fs::write(data_dir.join("root"), HELLOWORLD_BLOB_CONTENTS).unwrap(); + std::fs::write(tmpdir.path().join("root"), HELLOWORLD_BLOB_CONTENTS).unwrap(); - let mut blob_service = gen_blob_service(tmpdir.path()); + let mut blob_service = gen_blob_service(); let root_node = import_path( &mut blob_service, - &mut gen_chunk_service(tmpdir.path()), - &mut gen_directory_service(tmpdir.path()), - data_dir.join("root"), + &mut gen_chunk_service(), + &mut gen_directory_service(), + tmpdir.path().join("root"), ) .expect("must succeed"); @@ -76,34 +77,35 @@ fn single_file() { fn complicated() { let tmpdir = TempDir::new().unwrap(); - let data_dir = tmpdir.path().join("data"); - - // Populate path to import - std::fs::create_dir_all(&data_dir).unwrap(); // File ``.keep` - std::fs::write(data_dir.join(".keep"), vec![]).unwrap(); + std::fs::write(tmpdir.path().join(".keep"), vec![]).unwrap(); // Symlink `aa` - std::os::unix::fs::symlink("/nix/store/somewhereelse", data_dir.join("aa")).unwrap(); + std::os::unix::fs::symlink("/nix/store/somewhereelse", tmpdir.path().join("aa")).unwrap(); // Directory `keep` - std::fs::create_dir(data_dir.join("keep")).unwrap(); + std::fs::create_dir(tmpdir.path().join("keep")).unwrap(); // File ``keep/.keep` - std::fs::write(data_dir.join("keep").join(".keep"), vec![]).unwrap(); + std::fs::write(tmpdir.path().join("keep").join(".keep"), vec![]).unwrap(); - let mut blob_service = gen_blob_service(tmpdir.path()); - let mut directory_service = gen_directory_service(tmpdir.path()); + let mut blob_service = gen_blob_service(); + let mut directory_service = gen_directory_service(); let root_node = import_path( &mut blob_service, - &mut gen_chunk_service(tmpdir.path()), + &mut gen_chunk_service(), &mut directory_service, - data_dir, + tmpdir.path(), ) .expect("must succeed"); // ensure root_node matched expectations assert_eq!( crate::proto::node::Node::Directory(proto::DirectoryNode { - name: "data".to_string(), + name: tmpdir + .path() + .file_name() + .unwrap() + .to_string_lossy() + .to_string(), digest: DIRECTORY_COMPLICATED.digest(), size: DIRECTORY_COMPLICATED.size(), }), diff --git a/tvix/store/src/tests/nar_renderer.rs b/tvix/store/src/tests/nar_renderer.rs index 8c0f738b5143..2b5b4f705c64 100644 --- a/tvix/store/src/tests/nar_renderer.rs +++ b/tvix/store/src/tests/nar_renderer.rs @@ -8,15 +8,13 @@ use crate::proto::FileNode; use crate::proto::SymlinkNode; use crate::tests::fixtures::*; use crate::tests::utils::*; -use tempfile::TempDir; #[test] fn single_symlink() { - let tmpdir = TempDir::new().unwrap(); let renderer = NARRenderer::new( - gen_blob_service(tmpdir.path()), - gen_chunk_service(tmpdir.path()), - gen_directory_service(tmpdir.path()), + gen_blob_service(), + gen_chunk_service(), + gen_directory_service(), ); // don't put anything in the stores, as we don't actually do any requests. @@ -39,15 +37,10 @@ fn single_symlink() { /// match what's in the store. #[test] fn single_file_missing_blob() { - let tmpdir = TempDir::new().unwrap(); - - let blob_service = gen_blob_service(tmpdir.path()); - let chunk_service = gen_chunk_service(tmpdir.path()); - let renderer = NARRenderer::new( - blob_service, - chunk_service, - gen_directory_service(tmpdir.path()), + gen_blob_service(), + gen_chunk_service(), + gen_directory_service(), ); let mut buf: Vec<u8> = vec![]; @@ -74,10 +67,8 @@ fn single_file_missing_blob() { /// than specified in the proto node. #[test] fn single_file_wrong_blob_size() { - let tmpdir = TempDir::new().unwrap(); - - let blob_service = gen_blob_service(tmpdir.path()); - let chunk_service = gen_chunk_service(tmpdir.path()); + let blob_service = gen_blob_service(); + let chunk_service = gen_chunk_service(); // insert blob and chunk into the stores chunk_service @@ -97,11 +88,7 @@ fn single_file_wrong_blob_size() { ) .unwrap(); - let renderer = NARRenderer::new( - blob_service, - chunk_service, - gen_directory_service(tmpdir.path()), - ); + let renderer = NARRenderer::new(blob_service, chunk_service, gen_directory_service()); let mut buf: Vec<u8> = vec![]; let e = renderer @@ -138,10 +125,8 @@ fn single_file_wrong_blob_size() { #[test] fn single_file() { - let tmpdir = TempDir::new().unwrap(); - - let blob_service = gen_blob_service(tmpdir.path()); - let chunk_service = gen_chunk_service(tmpdir.path()); + let blob_service = gen_blob_service(); + let chunk_service = gen_chunk_service(); chunk_service .put(HELLOWORLD_BLOB_CONTENTS.to_vec()) @@ -160,11 +145,7 @@ fn single_file() { ) .unwrap(); - let renderer = NARRenderer::new( - blob_service, - chunk_service, - gen_directory_service(tmpdir.path()), - ); + let renderer = NARRenderer::new(blob_service, chunk_service, gen_directory_service()); let mut buf: Vec<u8> = vec![]; renderer @@ -184,11 +165,9 @@ fn single_file() { #[test] fn test_complicated() { - let tmpdir = TempDir::new().unwrap(); - - let blob_service = gen_blob_service(tmpdir.path()); - let chunk_service = gen_chunk_service(tmpdir.path()); - let directory_service = gen_directory_service(tmpdir.path()); + let blob_service = gen_blob_service(); + let chunk_service = gen_chunk_service(); + let directory_service = gen_directory_service(); // put all data into the stores. let digest = chunk_service.put(EMPTY_BLOB_CONTENTS.to_vec()).unwrap(); diff --git a/tvix/store/src/tests/utils.rs b/tvix/store/src/tests/utils.rs index 4ddd4102fb97..9da9d2643b81 100644 --- a/tvix/store/src/tests/utils.rs +++ b/tvix/store/src/tests/utils.rs @@ -1,5 +1,3 @@ -use std::path::Path; - use crate::{ blobservice::{BlobService, SledBlobService}, chunkservice::{ChunkService, SledChunkService}, @@ -7,18 +5,18 @@ use crate::{ pathinfoservice::{PathInfoService, SledPathInfoService}, }; -pub fn gen_blob_service(p: &Path) -> impl BlobService + Send + Sync + Clone + 'static { - SledBlobService::new(p.join("blobs")).unwrap() +pub fn gen_blob_service() -> impl BlobService + Send + Sync + Clone + 'static { + SledBlobService::new_temporary().unwrap() } -pub fn gen_chunk_service(p: &Path) -> impl ChunkService + Clone { - SledChunkService::new(p.join("chunks")).unwrap() +pub fn gen_chunk_service() -> impl ChunkService + Clone { + SledChunkService::new_temporary().unwrap() } -pub fn gen_directory_service(p: &Path) -> impl DirectoryService + Send + Sync + Clone + 'static { - SledDirectoryService::new(p.join("directories")).unwrap() +pub fn gen_directory_service() -> impl DirectoryService + Send + Sync + Clone + 'static { + SledDirectoryService::new_temporary().unwrap() } -pub fn gen_pathinfo_service(p: &Path) -> impl PathInfoService { - SledPathInfoService::new(p.join("pathinfo")).unwrap() +pub fn gen_pathinfo_service() -> impl PathInfoService { + SledPathInfoService::new_temporary().unwrap() } |