about summary refs log tree commit diff
path: root/tvix/store/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/store/src/tests')
-rw-r--r--tvix/store/src/tests/fixtures.rs85
-rw-r--r--tvix/store/src/tests/import.rs125
-rw-r--r--tvix/store/src/tests/mod.rs1
-rw-r--r--tvix/store/src/tests/nar_renderer.rs20
-rw-r--r--tvix/store/src/tests/utils.rs16
5 files changed, 15 insertions, 232 deletions
diff --git a/tvix/store/src/tests/fixtures.rs b/tvix/store/src/tests/fixtures.rs
index c362744a34a7..4d820af1578e 100644
--- a/tvix/store/src/tests/fixtures.rs
+++ b/tvix/store/src/tests/fixtures.rs
@@ -1,90 +1,9 @@
-use crate::{
-    proto::{self, Directory, DirectoryNode, FileNode, SymlinkNode},
-    B3Digest,
-};
 use lazy_static::lazy_static;
+pub use tvix_castore::fixtures::*;
 
-pub const HELLOWORLD_BLOB_CONTENTS: &[u8] = b"Hello World!";
-pub const EMPTY_BLOB_CONTENTS: &[u8] = b"";
+pub const DUMMY_NAME: &str = "00000000000000000000000000000000-dummy";
 
 lazy_static! {
-    pub static ref DUMMY_DIGEST: B3Digest = {
-        let u: &[u8; 32] = &[
-            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-            0x00, 0x00,
-        ];
-        u.into()
-    };
-    pub static ref DUMMY_DATA_1: bytes::Bytes = vec![0x01, 0x02, 0x03].into();
-    pub static ref DUMMY_DATA_2: bytes::Bytes = vec![0x04, 0x05].into();
-
-    pub static ref HELLOWORLD_BLOB_DIGEST: B3Digest =
-        blake3::hash(HELLOWORLD_BLOB_CONTENTS).as_bytes().into();
-    pub static ref EMPTY_BLOB_DIGEST: B3Digest =
-        blake3::hash(EMPTY_BLOB_CONTENTS).as_bytes().into();
-
-    // 2 bytes
-    pub static ref BLOB_A: bytes::Bytes = vec![0x00, 0x01].into();
-    pub static ref BLOB_A_DIGEST: B3Digest = blake3::hash(&BLOB_A).as_bytes().into();
-
-    // 1MB
-    pub static ref BLOB_B: bytes::Bytes = (0..255).collect::<Vec<u8>>().repeat(4 * 1024).into();
-    pub static ref BLOB_B_DIGEST: B3Digest = blake3::hash(&BLOB_B).as_bytes().into();
-
-    // Directories
-    pub static ref DIRECTORY_WITH_KEEP: proto::Directory = proto::Directory {
-        directories: vec![],
-        files: vec![FileNode {
-            name: b".keep".to_vec().into(),
-            digest: EMPTY_BLOB_DIGEST.clone().into(),
-            size: 0,
-            executable: false,
-        }],
-        symlinks: vec![],
-    };
-    pub static ref DIRECTORY_COMPLICATED: proto::Directory = proto::Directory {
-        directories: vec![DirectoryNode {
-            name: b"keep".to_vec().into(),
-            digest: DIRECTORY_WITH_KEEP.digest().into(),
-            size: DIRECTORY_WITH_KEEP.size(),
-        }],
-        files: vec![FileNode {
-            name: b".keep".to_vec().into(),
-            digest: EMPTY_BLOB_DIGEST.clone().into(),
-            size: 0,
-            executable: false,
-        }],
-        symlinks: vec![SymlinkNode {
-            name: b"aa".to_vec().into(),
-            target: b"/nix/store/somewhereelse".to_vec().into(),
-        }],
-    };
-    pub static ref DIRECTORY_A: Directory = Directory::default();
-    pub static ref DIRECTORY_B: Directory = Directory {
-        directories: vec![DirectoryNode {
-            name: b"a".to_vec().into(),
-            digest: DIRECTORY_A.digest().into(),
-            size: DIRECTORY_A.size(),
-        }],
-        ..Default::default()
-    };
-    pub static ref DIRECTORY_C: Directory = Directory {
-        directories: vec![
-            DirectoryNode {
-                name: b"a".to_vec().into(),
-                digest: DIRECTORY_A.digest().into(),
-                size: DIRECTORY_A.size(),
-            },
-            DirectoryNode {
-                name: b"a'".to_vec().into(),
-                digest: DIRECTORY_A.digest().into(),
-                size: DIRECTORY_A.size(),
-            }
-        ],
-        ..Default::default()
-    };
-
     // output hash
     pub static ref DUMMY_OUTPUT_HASH: bytes::Bytes = vec![
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
diff --git a/tvix/store/src/tests/import.rs b/tvix/store/src/tests/import.rs
deleted file mode 100644
index 3f7f7dff9db1..000000000000
--- a/tvix/store/src/tests/import.rs
+++ /dev/null
@@ -1,125 +0,0 @@
-use super::utils::{gen_blob_service, gen_directory_service};
-use crate::import::ingest_path;
-use crate::proto;
-use crate::tests::fixtures::DIRECTORY_COMPLICATED;
-use crate::tests::fixtures::*;
-use tempfile::TempDir;
-
-#[cfg(target_family = "unix")]
-use std::os::unix::ffi::OsStrExt;
-
-#[cfg(target_family = "unix")]
-#[tokio::test]
-async fn symlink() {
-    let tmpdir = TempDir::new().unwrap();
-
-    std::fs::create_dir_all(&tmpdir).unwrap();
-    std::os::unix::fs::symlink(
-        "/nix/store/somewhereelse",
-        tmpdir.path().join("doesntmatter"),
-    )
-    .unwrap();
-
-    let root_node = ingest_path(
-        gen_blob_service(),
-        gen_directory_service(),
-        tmpdir.path().join("doesntmatter"),
-    )
-    .await
-    .expect("must succeed");
-
-    assert_eq!(
-        crate::proto::node::Node::Symlink(proto::SymlinkNode {
-            name: "doesntmatter".into(),
-            target: "/nix/store/somewhereelse".into(),
-        }),
-        root_node,
-    )
-}
-
-#[tokio::test]
-async fn single_file() {
-    let tmpdir = TempDir::new().unwrap();
-
-    std::fs::write(tmpdir.path().join("root"), HELLOWORLD_BLOB_CONTENTS).unwrap();
-
-    let blob_service = gen_blob_service();
-
-    let root_node = ingest_path(
-        blob_service.clone(),
-        gen_directory_service(),
-        tmpdir.path().join("root"),
-    )
-    .await
-    .expect("must succeed");
-
-    assert_eq!(
-        crate::proto::node::Node::File(proto::FileNode {
-            name: "root".into(),
-            digest: HELLOWORLD_BLOB_DIGEST.clone().into(),
-            size: HELLOWORLD_BLOB_CONTENTS.len() as u32,
-            executable: false,
-        }),
-        root_node,
-    );
-
-    // ensure the blob has been uploaded
-    assert!(blob_service.has(&HELLOWORLD_BLOB_DIGEST).await.unwrap());
-}
-
-#[cfg(target_family = "unix")]
-#[tokio::test]
-async fn complicated() {
-    let tmpdir = TempDir::new().unwrap();
-
-    // File ``.keep`
-    std::fs::write(tmpdir.path().join(".keep"), vec![]).unwrap();
-    // Symlink `aa`
-    std::os::unix::fs::symlink("/nix/store/somewhereelse", tmpdir.path().join("aa")).unwrap();
-    // Directory `keep`
-    std::fs::create_dir(tmpdir.path().join("keep")).unwrap();
-    // File ``keep/.keep`
-    std::fs::write(tmpdir.path().join("keep").join(".keep"), vec![]).unwrap();
-
-    let blob_service = gen_blob_service();
-    let directory_service = gen_directory_service();
-
-    let root_node = ingest_path(
-        blob_service.clone(),
-        directory_service.clone(),
-        tmpdir.path(),
-    )
-    .await
-    .expect("must succeed");
-
-    // ensure root_node matched expectations
-    assert_eq!(
-        crate::proto::node::Node::Directory(proto::DirectoryNode {
-            name: tmpdir
-                .path()
-                .file_name()
-                .unwrap()
-                .as_bytes()
-                .to_owned()
-                .into(),
-            digest: DIRECTORY_COMPLICATED.digest().into(),
-            size: DIRECTORY_COMPLICATED.size(),
-        }),
-        root_node,
-    );
-
-    // ensure DIRECTORY_WITH_KEEP and DIRECTORY_COMPLICATED have been uploaded
-    assert!(directory_service
-        .get(&DIRECTORY_WITH_KEEP.digest())
-        .await
-        .unwrap()
-        .is_some());
-    assert!(directory_service
-        .get(&DIRECTORY_COMPLICATED.digest())
-        .await
-        .unwrap()
-        .is_some());
-
-    // ensure EMPTY_BLOB_CONTENTS has been uploaded
-    assert!(blob_service.has(&EMPTY_BLOB_DIGEST).await.unwrap());
-}
diff --git a/tvix/store/src/tests/mod.rs b/tvix/store/src/tests/mod.rs
index 8ceea01e3190..daea048deddf 100644
--- a/tvix/store/src/tests/mod.rs
+++ b/tvix/store/src/tests/mod.rs
@@ -1,4 +1,3 @@
 pub mod fixtures;
-mod import;
 mod nar_renderer;
 pub mod utils;
diff --git a/tvix/store/src/tests/nar_renderer.rs b/tvix/store/src/tests/nar_renderer.rs
index e0163dc7bd93..485d7d115ff5 100644
--- a/tvix/store/src/tests/nar_renderer.rs
+++ b/tvix/store/src/tests/nar_renderer.rs
@@ -1,12 +1,12 @@
 use crate::nar::calculate_size_and_sha256;
 use crate::nar::write_nar;
-use crate::proto::DirectoryNode;
-use crate::proto::FileNode;
-use crate::proto::SymlinkNode;
 use crate::tests::fixtures::*;
 use crate::tests::utils::*;
 use sha2::{Digest, Sha256};
 use std::io;
+use tvix_castore::proto::DirectoryNode;
+use tvix_castore::proto::FileNode;
+use tvix_castore::proto::{self as castorepb, SymlinkNode};
 
 #[tokio::test]
 async fn single_symlink() {
@@ -14,7 +14,7 @@ async fn single_symlink() {
 
     let buf = write_nar(
         buf,
-        &crate::proto::node::Node::Symlink(SymlinkNode {
+        &castorepb::node::Node::Symlink(SymlinkNode {
             name: "doesntmatter".into(),
             target: "/nix/store/somewhereelse".into(),
         }),
@@ -35,7 +35,7 @@ async fn single_file_missing_blob() {
 
     let e = write_nar(
         buf,
-        &crate::proto::node::Node::File(FileNode {
+        &castorepb::node::Node::File(FileNode {
             name: "doesntmatter".into(),
             digest: HELLOWORLD_BLOB_DIGEST.clone().into(),
             size: HELLOWORLD_BLOB_CONTENTS.len() as u32,
@@ -82,7 +82,7 @@ async fn single_file_wrong_blob_size() {
 
         let e = write_nar(
             buf,
-            &crate::proto::node::Node::File(FileNode {
+            &castorepb::node::Node::File(FileNode {
                 name: "doesntmatter".into(),
                 digest: HELLOWORLD_BLOB_DIGEST.clone().into(),
                 size: 42, // <- note the wrong size here!
@@ -109,7 +109,7 @@ async fn single_file_wrong_blob_size() {
 
         let e = write_nar(
             buf,
-            &crate::proto::node::Node::File(FileNode {
+            &castorepb::node::Node::File(FileNode {
                 name: "doesntmatter".into(),
                 digest: HELLOWORLD_BLOB_DIGEST.clone().into(),
                 size: 2, // <- note the wrong size here!
@@ -152,7 +152,7 @@ async fn single_file() {
 
     let buf = write_nar(
         buf,
-        &crate::proto::node::Node::File(FileNode {
+        &castorepb::node::Node::File(FileNode {
             name: "doesntmatter".into(),
             digest: HELLOWORLD_BLOB_DIGEST.clone().into(),
             size: HELLOWORLD_BLOB_CONTENTS.len() as u32,
@@ -199,7 +199,7 @@ async fn test_complicated() {
 
     let buf = write_nar(
         buf,
-        &crate::proto::node::Node::Directory(DirectoryNode {
+        &castorepb::node::Node::Directory(DirectoryNode {
             name: "doesntmatter".into(),
             digest: DIRECTORY_COMPLICATED.digest().into(),
             size: DIRECTORY_COMPLICATED.size(),
@@ -216,7 +216,7 @@ async fn test_complicated() {
     let bs = blob_service.clone();
     let ds = directory_service.clone();
     let (nar_size, nar_digest) = calculate_size_and_sha256(
-        &crate::proto::node::Node::Directory(DirectoryNode {
+        &castorepb::node::Node::Directory(DirectoryNode {
             name: "doesntmatter".into(),
             digest: DIRECTORY_COMPLICATED.digest().into(),
             size: DIRECTORY_COMPLICATED.size(),
diff --git a/tvix/store/src/tests/utils.rs b/tvix/store/src/tests/utils.rs
index 9ccd3dcc65b7..961be6e7ac07 100644
--- a/tvix/store/src/tests/utils.rs
+++ b/tvix/store/src/tests/utils.rs
@@ -1,18 +1,8 @@
+use crate::pathinfoservice::{MemoryPathInfoService, PathInfoService};
 use std::sync::Arc;
+use tvix_castore::{blobservice::BlobService, directoryservice::DirectoryService};
 
-use crate::{
-    blobservice::{BlobService, MemoryBlobService},
-    directoryservice::{DirectoryService, MemoryDirectoryService},
-    pathinfoservice::{MemoryPathInfoService, PathInfoService},
-};
-
-pub fn gen_blob_service() -> Arc<dyn BlobService> {
-    Arc::new(MemoryBlobService::default())
-}
-
-pub fn gen_directory_service() -> Arc<dyn DirectoryService> {
-    Arc::new(MemoryDirectoryService::default())
-}
+pub use tvix_castore::utils::*;
 
 pub fn gen_pathinfo_service(
     blob_service: Arc<dyn BlobService>,