about summary refs log tree commit diff
path: root/tvix/store/src/tests/fixtures.rs
diff options
context:
space:
mode:
authorMarijan Petričević <marijan.petricevic94@gmail.com>2024-10-10T14·11-0500
committerMarijan Petričević <marijan.petricevic94@gmail.com>2024-10-11T17·18+0000
commite8040ec61f2119ece2d396704576973f704607f3 (patch)
tree94caa469edb4b6c5534eb19a9683d786f9b7e5bf /tvix/store/src/tests/fixtures.rs
parentb4ccaac7ad135249eb0b1866acf4c8e68fd5bdb9 (diff)
refactor(tvix/store): use strictly typed PathInfo struct r/8787
This switches the PathInfoService trait from using the proto-derived
PathInfo struct to a more restrictive struct, and updates all
implementations to use it.

It removes a lot of the previous conversion and checks, as invalid
states became nonrepresentable, and validations are expressed on the
type level.

PathInfoService implementations consuming protobuf need to convert and
do the verification internally, and can only return the strongly typed
variant.

The nix_compat::narinfo::NarInfo conversions for the proto PathInfo
are removed, we only keep a version showing a NarInfo representation for
the strong struct.

Converting back to a PathInfo requires the root node now, but is
otherwise trivial, so left to the users.

Co-Authored-By: Florian Klink <flokli@flokli.de>
Change-Id: I6fdfdb44063efebb44a8f0097b6b81a828717e03
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12588
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/store/src/tests/fixtures.rs')
-rw-r--r--tvix/store/src/tests/fixtures.rs58
1 files changed, 24 insertions, 34 deletions
diff --git a/tvix/store/src/tests/fixtures.rs b/tvix/store/src/tests/fixtures.rs
index 48cc365365a9..91628f2fee79 100644
--- a/tvix/store/src/tests/fixtures.rs
+++ b/tvix/store/src/tests/fixtures.rs
@@ -1,24 +1,27 @@
+use crate::pathinfoservice::PathInfo;
 use lazy_static::lazy_static;
+use nix_compat::nixhash::{CAHash, NixHash};
+use nix_compat::store_path::StorePath;
 use rstest::{self, *};
 use rstest_reuse::*;
 use std::io;
 use std::sync::Arc;
-pub use tvix_castore::fixtures::*;
+use tvix_castore::fixtures::{
+    DIRECTORY_COMPLICATED, DIRECTORY_WITH_KEEP, DUMMY_DIGEST, EMPTY_BLOB_CONTENTS,
+    EMPTY_BLOB_DIGEST, HELLOWORLD_BLOB_CONTENTS, HELLOWORLD_BLOB_DIGEST,
+};
 use tvix_castore::{
     blobservice::{BlobService, MemoryBlobService},
     directoryservice::{DirectoryService, MemoryDirectoryService},
-    proto as castorepb, Node,
-};
-
-use crate::proto::{
-    nar_info::{ca, Ca},
-    NarInfo, PathInfo,
+    Node,
 };
 
-pub const DUMMY_PATH: &str = "00000000000000000000000000000000-dummy";
+pub const DUMMY_PATH_STR: &str = "00000000000000000000000000000000-dummy";
 pub const DUMMY_PATH_DIGEST: [u8; 20] = [0; 20];
 
 lazy_static! {
+    pub static ref DUMMY_PATH: StorePath<String> = StorePath::from_name_and_digest_fixed("dummy", DUMMY_PATH_DIGEST).unwrap();
+
     pub static ref CASTORE_NODE_SYMLINK: Node = Node::Symlink {
         target: "/nix/store/somewhereelse".try_into().unwrap(),
     };
@@ -130,32 +133,19 @@ lazy_static! {
         1, 0, 0, 0, 0, 0, 0, 0, b')', 0, 0, 0, 0, 0, 0, 0, // ")"
     ];
 
-    /// A PathInfo message without .narinfo populated.
-    pub static ref PATH_INFO_WITHOUT_NARINFO : PathInfo = PathInfo {
-        node: Some(castorepb::Node {
-            node: Some(castorepb::node::Node::Directory(castorepb::DirectoryNode {
-                name: DUMMY_PATH.into(),
-                digest: DUMMY_DIGEST.clone().into(),
-                size: 0,
-            })),
-        }),
-        references: vec![DUMMY_PATH_DIGEST.as_slice().into()],
-        narinfo: None,
-    };
-
-    /// A PathInfo message with .narinfo populated.
-    /// The references in `narinfo.reference_names` aligns with what's in
-    /// `references`.
-    pub static ref PATH_INFO_WITH_NARINFO : PathInfo = PathInfo {
-        narinfo: Some(NarInfo {
-            nar_size: 0,
-            nar_sha256: DUMMY_DIGEST.clone().into(),
-            signatures: vec![],
-            reference_names: vec![DUMMY_PATH.to_string()],
-            deriver: None,
-            ca: Some(Ca { r#type: ca::Hash::NarSha256.into(), digest:  DUMMY_DIGEST.clone().into() })
-        }),
-      ..PATH_INFO_WITHOUT_NARINFO.clone()
+    /// A PathInfo message
+    pub static ref PATH_INFO: PathInfo = PathInfo {
+        store_path: DUMMY_PATH.clone(),
+        node: tvix_castore::Node::Directory {
+            digest: DUMMY_DIGEST.clone(),
+            size: 0,
+        },
+        references: vec![DUMMY_PATH.clone()],
+        nar_sha256: [0; 32],
+        nar_size: 0,
+        signatures: vec![],
+        deriver: None,
+        ca: Some(CAHash::Nar(NixHash::Sha256([0; 32]))),
     };
 }