about summary refs log tree commit diff
path: root/tvix/store/src/proto
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-02-27T07·59+0100
committerflokli <flokli@flokli.de>2023-03-10T10·58+0000
commit28a862976bd43912e0e5dc16e8919590c36f4cf0 (patch)
treef6e6fb7eac5145c9519ff8399a14ab1733a75c66 /tvix/store/src/proto
parent0baaabc43e3027b1676874c536d5ade27abe14b8 (diff)
refactor(tvix/store/tests): move gen_*_service() into helper r/5928
This allows hiding to tests what exact implementation we're using, when
testing things that do something with a store, but don't care what's
used for underlying storage.

Change-Id: I7cdf60fd73c25d5050159cb31ec177db2bc2a7f1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8155
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Diffstat (limited to 'tvix/store/src/proto')
-rw-r--r--tvix/store/src/proto/tests/grpc_blobservice.rs9
-rw-r--r--tvix/store/src/proto/tests/grpc_directoryservice.rs9
-rw-r--r--tvix/store/src/proto/tests/grpc_pathinfoservice.rs49
3 files changed, 24 insertions, 43 deletions
diff --git a/tvix/store/src/proto/tests/grpc_blobservice.rs b/tvix/store/src/proto/tests/grpc_blobservice.rs
index cd8ae3e2bf..b409fc3ea3 100644
--- a/tvix/store/src/proto/tests/grpc_blobservice.rs
+++ b/tvix/store/src/proto/tests/grpc_blobservice.rs
@@ -1,8 +1,9 @@
-use crate::blobservice::{BlobService, SledBlobService};
-use crate::chunkservice::{ChunkService, SledChunkService};
+use crate::blobservice::BlobService;
+use crate::chunkservice::ChunkService;
 use crate::proto::blob_meta::ChunkMeta;
 use crate::proto::blob_service_server::BlobService as GRPCBlobService;
 use crate::proto::{BlobChunk, GRPCBlobServiceWrapper, ReadBlobRequest, StatBlobRequest};
+use crate::tests::utils::{gen_blob_service, gen_chunk_service};
 use lazy_static::lazy_static;
 use std::path::Path;
 use tempfile::TempDir;
@@ -23,8 +24,8 @@ fn gen_grpc_blob_service(
     impl BlobService + Send + Sync + Clone + 'static,
     impl ChunkService + Send + Sync + Clone + 'static,
 > {
-    let blob_service = SledBlobService::new(p.join("blobs")).unwrap();
-    let chunk_service = SledChunkService::new(p.join("chunks")).unwrap();
+    let blob_service = gen_blob_service(p);
+    let chunk_service = gen_chunk_service(p);
     GRPCBlobServiceWrapper::new(blob_service, chunk_service)
 }
 
diff --git a/tvix/store/src/proto/tests/grpc_directoryservice.rs b/tvix/store/src/proto/tests/grpc_directoryservice.rs
index 58d49811f0..b004c47c2d 100644
--- a/tvix/store/src/proto/tests/grpc_directoryservice.rs
+++ b/tvix/store/src/proto/tests/grpc_directoryservice.rs
@@ -1,8 +1,9 @@
-use crate::directoryservice::SledDirectoryService;
+use crate::directoryservice::DirectoryService;
 use crate::proto::directory_service_server::DirectoryService as GRPCDirectoryService;
 use crate::proto::get_directory_request::ByWhat;
 use crate::proto::{Directory, DirectoryNode, SymlinkNode};
 use crate::proto::{GRPCDirectoryServiceWrapper, GetDirectoryRequest};
+use crate::tests::utils::gen_directory_service;
 use lazy_static::lazy_static;
 use std::path::Path;
 use tempfile::TempDir;
@@ -36,8 +37,10 @@ lazy_static! {
     };
 }
 
-fn gen_grpc_service(p: &Path) -> GRPCDirectoryServiceWrapper<SledDirectoryService> {
-    let directory_service = SledDirectoryService::new(p.join("directories")).unwrap();
+fn gen_grpc_service(
+    p: &Path,
+) -> GRPCDirectoryServiceWrapper<impl DirectoryService + Send + Sync + Clone + 'static> {
+    let directory_service = gen_directory_service(p);
     GRPCDirectoryServiceWrapper::from(directory_service)
 }
 
diff --git a/tvix/store/src/proto/tests/grpc_pathinfoservice.rs b/tvix/store/src/proto/tests/grpc_pathinfoservice.rs
index 3858909757..a6a1de9dc4 100644
--- a/tvix/store/src/proto/tests/grpc_pathinfoservice.rs
+++ b/tvix/store/src/proto/tests/grpc_pathinfoservice.rs
@@ -1,21 +1,17 @@
-use std::path::Path;
-
-use tempfile::TempDir;
-use tonic::Request;
-
-use crate::blobservice::{BlobService, SledBlobService};
-use crate::chunkservice::{ChunkService, SledChunkService};
-use crate::directoryservice::{DirectoryService, SledDirectoryService};
 use crate::nar::NonCachingNARCalculationService;
-use crate::pathinfoservice::{PathInfoService, SledPathInfoService};
 use crate::proto::get_path_info_request::ByWhat::ByOutputHash;
 use crate::proto::node::Node::Symlink;
 use crate::proto::path_info_service_server::PathInfoService as GRPCPathInfoService;
 use crate::proto::GRPCPathInfoServiceWrapper;
 use crate::proto::PathInfo;
 use crate::proto::{GetPathInfoRequest, Node, SymlinkNode};
-
+use crate::tests::utils::{
+    gen_blob_service, gen_chunk_service, gen_directory_service, gen_pathinfo_service,
+};
 use lazy_static::lazy_static;
+use std::path::Path;
+use tempfile::TempDir;
+use tonic::Request;
 
 lazy_static! {
     static ref DUMMY_OUTPUT_HASH: Vec<u8> = vec![
@@ -24,38 +20,19 @@ lazy_static! {
     ];
 }
 
-// TODO: dedup these helpers
-fn gen_pathinfo_service(p: &Path) -> impl PathInfoService {
-    SledPathInfoService::new(p.join("pathinfo")).unwrap()
-}
-fn gen_blob_service(p: &Path) -> impl BlobService {
-    SledBlobService::new(p.join("blobs")).unwrap()
-}
-
-fn gen_chunk_service(p: &Path) -> impl ChunkService + Clone {
-    SledChunkService::new(p.join("chunks")).unwrap()
-}
-
-fn gen_directory_service(p: &Path) -> impl DirectoryService {
-    SledDirectoryService::new(p.join("directories")).unwrap()
-}
-
 /// generates a GRPCPathInfoService out of blob, chunk, directory and pathinfo services.
 ///
-/// It doesn't create underlying services on its own, as we don't need to
-/// preseed them with existing data for the test - we only interact with it via
-// the PathInfo GRPC interface.
+/// We only interact with it via the PathInfo GRPC interface.
 /// It uses the NonCachingNARCalculationService NARCalculationService to
 /// calculate NARs.
 fn gen_grpc_service(p: &Path) -> impl GRPCPathInfoService {
-    let blob_service = gen_blob_service(p);
-    let chunk_service = gen_chunk_service(p);
-    let directory_service = gen_directory_service(p);
-    let pathinfo_service = gen_pathinfo_service(p);
-
     GRPCPathInfoServiceWrapper::new(
-        pathinfo_service,
-        NonCachingNARCalculationService::new(blob_service, chunk_service, directory_service),
+        gen_pathinfo_service(p),
+        NonCachingNARCalculationService::new(
+            gen_blob_service(p),
+            gen_chunk_service(p),
+            gen_directory_service(p),
+        ),
     )
 }