about summary refs log tree commit diff
path: root/tvix/store/src/proto/tests
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-03-15T23·01+0100
committerflokli <flokli@flokli.de>2023-03-16T13·47+0000
commitee23220564987771c8e7909ded6fb9853f1d1b0d (patch)
treeb1c99097c8912642c9f3582adebff49f9caa3093 /tvix/store/src/proto/tests
parent9c08cbc9732710a0003cb7bbe0ff7a9950fc22b6 (diff)
refactor(tvix/store/directorysvc): use [u8; 32] instead of Vec<u8> r/6014
Also, simplify the trait interface, only allowing lookups of Directory
objects by their digest.

Change-Id: I6eec28a8cb0557bed9b69df8b8ff99a5e0f8fe35
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8313
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/store/src/proto/tests')
-rw-r--r--tvix/store/src/proto/tests/directory.rs4
-rw-r--r--tvix/store/src/proto/tests/grpc_directoryservice.rs20
2 files changed, 15 insertions, 9 deletions
diff --git a/tvix/store/src/proto/tests/directory.rs b/tvix/store/src/proto/tests/directory.rs
index 890cb2164ad5..03572629e606 100644
--- a/tvix/store/src/proto/tests/directory.rs
+++ b/tvix/store/src/proto/tests/directory.rs
@@ -2,7 +2,7 @@ use crate::proto::{Directory, DirectoryNode, FileNode, SymlinkNode, ValidateDire
 use lazy_static::lazy_static;
 
 lazy_static! {
-    static ref DUMMY_DIGEST: Vec<u8> = vec![
+    static ref DUMMY_DIGEST: [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,
@@ -66,7 +66,7 @@ fn digest() {
 
     assert_eq!(
         d.digest(),
-        vec![
+        [
             0xaf, 0x13, 0x49, 0xb9, 0xf5, 0xf9, 0xa1, 0xa6, 0xa0, 0x40, 0x4d, 0xea, 0x36, 0xdc,
             0xc9, 0x49, 0x9b, 0xcb, 0x25, 0xc9, 0xad, 0xc1, 0x12, 0xb7, 0xcc, 0x9a, 0x93, 0xca,
             0xe4, 0x1f, 0x32, 0x62
diff --git a/tvix/store/src/proto/tests/grpc_directoryservice.rs b/tvix/store/src/proto/tests/grpc_directoryservice.rs
index 464c25f33d75..37428fbfa339 100644
--- a/tvix/store/src/proto/tests/grpc_directoryservice.rs
+++ b/tvix/store/src/proto/tests/grpc_directoryservice.rs
@@ -44,7 +44,7 @@ async fn not_found() {
 
     let resp = service
         .get(tonic::Request::new(GetDirectoryRequest {
-            by_what: Some(ByWhat::Digest(DIRECTORY_A.digest())),
+            by_what: Some(ByWhat::Digest(DIRECTORY_A.digest().to_vec())),
             ..Default::default()
         }))
         .await;
@@ -114,14 +114,17 @@ async fn put_get_multiple() {
         .await
         .expect("must succeed");
 
-    assert_eq!(DIRECTORY_B.digest(), put_resp.into_inner().root_digest);
+    assert_eq!(
+        DIRECTORY_B.digest().to_vec(),
+        put_resp.into_inner().root_digest
+    );
 
     // now, request b, first in non-recursive mode.
     let items = get_directories(
         &service,
         GetDirectoryRequest {
             recursive: false,
-            by_what: Some(ByWhat::Digest(DIRECTORY_B.digest())),
+            by_what: Some(ByWhat::Digest(DIRECTORY_B.digest().to_vec())),
         },
     )
     .await
@@ -135,7 +138,7 @@ async fn put_get_multiple() {
         &service,
         GetDirectoryRequest {
             recursive: true,
-            by_what: Some(ByWhat::Digest(DIRECTORY_B.digest())),
+            by_what: Some(ByWhat::Digest(DIRECTORY_B.digest().to_vec())),
         },
     )
     .await
@@ -161,14 +164,17 @@ async fn put_get_dedup() {
         .await
         .expect("must succeed");
 
-    assert_eq!(DIRECTORY_C.digest(), put_resp.into_inner().root_digest);
+    assert_eq!(
+        DIRECTORY_C.digest().to_vec(),
+        put_resp.into_inner().root_digest
+    );
 
     // Ask for "C" recursively. We expect to only get "A" once, as there's no point sending it twice.
     let items = get_directories(
         &service,
         GetDirectoryRequest {
             recursive: true,
-            by_what: Some(ByWhat::Digest(DIRECTORY_C.digest())),
+            by_what: Some(ByWhat::Digest(DIRECTORY_C.digest().to_vec())),
         },
     )
     .await
@@ -211,7 +217,7 @@ async fn put_reject_wrong_size() {
     let broken_parent_directory = Directory {
         directories: vec![DirectoryNode {
             name: "foo".to_string(),
-            digest: DIRECTORY_A.digest(),
+            digest: DIRECTORY_A.digest().to_vec(),
             size: 42,
         }],
         ..Default::default()