about summary refs log tree commit diff
path: root/tvix/store/src/tests/import.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-03-01T17·55+0100
committerflokli <flokli@flokli.de>2023-03-10T10·58+0000
commita4f6c4181aa7f975b1c3aad8d3fb30021388e014 (patch)
treeee2f0a3911503ccb66f29d5b47dbdd763c02b026 /tvix/store/src/tests/import.rs
parent535e1b15ab457c9015baebf14bd7b50a38edadb4 (diff)
feat(tvix/store): add new_temporary for all Sled services r/5934
This provides a service using /dev/shm, that's deleted once the
reference is dropped.

Refactor all tests to use these, which allows getting rid of most
TempDir usage in the tests.

The only place where we still use TempDir is in the importer tests,
which work on a filesystem path.

Change-Id: I08a950aa774bf9b46d9f5c92edf5efba36053242
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8193
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/store/src/tests/import.rs')
-rw-r--r--tvix/store/src/tests/import.rs56
1 files changed, 29 insertions, 27 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(),
         }),