refactor(tvix/castore): add RootNode impl for BTreeMap, mv fs tests

cl/10378 did already move store/fs to castore/fs, but we kept the tests
in tvix-store, as they were populating a PathInfoService to make nodes
appear in the mount root.

Update these tests to now just insert root nodes into a BTreeMap, and
ensure we can use that as a RootNodes too.

Change-Id: Iad7d1ee4f9423eb6e3a1da33f433842c9ae0de1f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10410
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
This commit is contained in:
Florian Klink 2023-12-23 12:24:14 +02:00 committed by clbot
parent 6af17545bf
commit 8d86d2f409
7 changed files with 305 additions and 306 deletions

1
tvix/Cargo.lock generated
View file

@ -3244,7 +3244,6 @@ dependencies = [
"data-encoding",
"futures",
"lazy_static",
"libc",
"nix-compat",
"pin-project-lite",
"prost",

View file

@ -10267,10 +10267,6 @@ rec {
}
];
devDependencies = [
{
name = "libc";
packageId = "libc";
}
{
name = "tempfile";
packageId = "tempfile";

View file

@ -9,6 +9,9 @@ pub mod fuse;
#[cfg(feature = "virtiofs")]
pub mod virtiofs;
#[cfg(test)]
mod tests;
use crate::proto as castorepb;
use crate::{
blobservice::{BlobReader, BlobService},

View file

@ -1,6 +1,7 @@
use std::pin::Pin;
use std::{collections::BTreeMap, ops::Deref, pin::Pin};
use crate::{proto::node::Node, Error};
use bytes::Bytes;
use futures::Stream;
use tonic::async_trait;
@ -14,5 +15,21 @@ pub trait RootNodes: Send + Sync {
/// Lists all root CA nodes in the filesystem. An error can be returned
/// in case listing is not allowed
fn list(&self) -> Pin<Box<dyn Stream<Item = Result<Node, Error>> + Send>>;
fn list(&self) -> Pin<Box<dyn Stream<Item = Result<Node, Error>> + Send + '_>>;
}
#[async_trait]
/// Implements RootNodes for something deref'ing to a BTreeMap of Nodes, where
/// the key is the node name.
impl<T> RootNodes for T
where
T: Deref<Target = BTreeMap<Bytes, Node>> + Send + Sync,
{
async fn get_by_basename(&self, name: &[u8]) -> Result<Option<Node>, Error> {
Ok(self.get(name).cloned())
}
fn list(&self) -> Pin<Box<dyn Stream<Item = Result<Node, Error>> + Send + '_>> {
Box::pin(tokio_stream::iter(self.iter().map(|(_, v)| Ok(v.clone()))))
}
}

View file

@ -47,9 +47,6 @@ test-case = "2.2.2"
tempfile = "3.3.0"
tokio-retry = "0.3.0"
[dev-dependencies.libc]
version = "0.2.144"
[features]
default = ["fuse", "tonic-reflection"]
fuse = ["tvix-castore/fuse"]

View file

@ -10,9 +10,6 @@ use tvix_castore::{blobservice::BlobService, directoryservice::DirectoryService}
use super::PathInfoService;
#[cfg(test)]
mod tests;
/// Helper to construct a [TvixStoreFs] from a [BlobService], [DirectoryService]
/// and [PathInfoService].
/// This avoids users to have to interact with the wrapper struct directly, as