about summary refs log tree commit diff
path: root/tvix/store/src/tests/path_info_service.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2022-12-29T20·39+0100
committerflokli <flokli@flokli.de>2023-01-12T10·11+0000
commit43f6aec384978da8ba554f14ba89959051b47d94 (patch)
tree2359f79ec564a748b6d3bcd7b9daf83db3af4aa1 /tvix/store/src/tests/path_info_service.rs
parentcfa42fd19aa58ee10d3b1660f4f1bb7b2efdfccc (diff)
feat(tvix/store): implement PathInfoService with sled r/5649
This uses [sled](https://github.com/spacejam/sled) to store PathInfo
objects.

Change-Id: I12e8032e5562af8f884efa23a78049fd1108fdbc
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7726
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/store/src/tests/path_info_service.rs')
-rw-r--r--tvix/store/src/tests/path_info_service.rs74
1 files changed, 74 insertions, 0 deletions
diff --git a/tvix/store/src/tests/path_info_service.rs b/tvix/store/src/tests/path_info_service.rs
new file mode 100644
index 000000000000..dca61fe12a56
--- /dev/null
+++ b/tvix/store/src/tests/path_info_service.rs
@@ -0,0 +1,74 @@
+use tempfile::TempDir;
+
+use crate::proto::path_info_service_server::PathInfoService;
+use crate::proto::GetPathInfoRequest;
+use crate::proto::{get_path_info_request, PathInfo};
+use crate::sled_path_info_service::SledPathInfoService;
+
+use lazy_static::lazy_static;
+
+lazy_static! {
+    static ref DUMMY_OUTPUT_HASH: Vec<u8> = vec![
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00
+    ];
+}
+
+/// Trying to get a non-existent PathInfo should return a not found error.
+#[tokio::test]
+async fn not_found() -> anyhow::Result<()> {
+    let service = SledPathInfoService::new(TempDir::new()?.path().to_path_buf())?;
+
+    let resp = service
+        .get(tonic::Request::new(GetPathInfoRequest {
+            by_what: Some(get_path_info_request::ByWhat::ByOutputHash(
+                DUMMY_OUTPUT_HASH.to_vec(),
+            )),
+        }))
+        .await;
+
+    match resp {
+        Err(status) => {
+            assert_eq!(status.code(), tonic::Code::NotFound);
+        }
+        Ok(_) => panic!("must fail"),
+    };
+
+    Ok(())
+}
+
+/// Put a PathInfo into the store, get it back.
+#[tokio::test]
+async fn put_get() -> anyhow::Result<()> {
+    let service = SledPathInfoService::new(TempDir::new()?.path().to_path_buf())?;
+
+    let path_info = PathInfo {
+        node: Some(crate::proto::Node {
+            node: Some(crate::proto::node::Node::Symlink(
+                crate::proto::SymlinkNode {
+                    name: "00000000000000000000000000000000-foo".to_string(),
+                    target: "doesntmatter".to_string(),
+                },
+            )),
+        }),
+        ..Default::default()
+    };
+
+    let resp = service.put(tonic::Request::new(path_info.clone())).await;
+
+    assert!(resp.is_ok());
+    assert_eq!(resp.expect("must succeed").into_inner(), path_info);
+
+    let resp = service
+        .get(tonic::Request::new(GetPathInfoRequest {
+            by_what: Some(get_path_info_request::ByWhat::ByOutputHash(
+                DUMMY_OUTPUT_HASH.to_vec(),
+            )),
+        }))
+        .await;
+
+    assert!(resp.is_ok());
+    assert_eq!(resp.expect("must succeed").into_inner(), path_info);
+
+    Ok(())
+}