refactor(tvix/castore): move src/fs/test into fuse mod

These tests only interact with the FUSE layer, and
import super::fuse to do its work.

However, this only works if the `fuse` feature is enabled, which we
don't do if we enable the `virtiofs` feature only, causing the tests
to fail:

```
❯ cargo test --no-default-features --features virtiofs
   Compiling tvix-castore v0.1.0 (/home/flokli/dev/nixos/code.tvl.fyi-submit2/tvix/castore)
error[E0432]: unresolved import `super::fuse`
  --> castore/src/fs/tests.rs:14:13
   |
14 | use super::{fuse::FuseDaemon, TvixStoreFs};
   |             ^^^^ could not find `fuse` in `super`
```

We move src/fs/tests.rs to src/fs/fuse/tests.rs
(and src/fs/fuse.rs to src/fs/fuse/mod.rs) to better structure this,
which will automatically cause both tests and code to only be built if
we have the `fuse` feature enabled.

Change-Id: I8fbbad3e4457e326bdfd171aa5c43d25d3187b5b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11715
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
Florian Klink 2024-05-26 16:21:48 +02:00 committed by clbot
parent 61cf4905fe
commit 9586e5c30d
3 changed files with 9 additions and 8 deletions

View file

@ -3,6 +3,9 @@ use std::{io, path::Path, sync::Arc, thread};
use fuse_backend_rs::{api::filesystem::FileSystem, transport::FuseSession};
use tracing::{error, instrument};
#[cfg(test)]
mod tests;
struct FuseServer<FS>
where
FS: FileSystem + Sync + Send,

View file

@ -11,7 +11,8 @@ use std::{
use tempfile::TempDir;
use tokio_stream::{wrappers::ReadDirStream, StreamExt};
use super::{fuse::FuseDaemon, TvixStoreFs};
use super::FuseDaemon;
use crate::fs::{TvixStoreFs, XATTR_NAME_BLOB_DIGEST, XATTR_NAME_DIRECTORY_DIGEST};
use crate::proto as castorepb;
use crate::proto::node::Node;
use crate::{
@ -614,12 +615,12 @@ async fn xattr() {
// There should be 1 key, XATTR_NAME_DIRECTORY_DIGEST.
assert_eq!(1, xattr_names.len(), "there should be 1 xattr name");
assert_eq!(
super::XATTR_NAME_DIRECTORY_DIGEST,
XATTR_NAME_DIRECTORY_DIGEST,
xattr_names.first().unwrap().as_encoded_bytes()
);
// The key should equal to the string-formatted b3 digest.
let val = xattr::get(&p, OsStr::from_bytes(super::XATTR_NAME_DIRECTORY_DIGEST))
let val = xattr::get(&p, OsStr::from_bytes(XATTR_NAME_DIRECTORY_DIGEST))
.expect("must succeed")
.expect("must be some");
assert_eq!(
@ -643,12 +644,12 @@ async fn xattr() {
// There should be 1 key, XATTR_NAME_BLOB_DIGEST.
assert_eq!(1, xattr_names.len(), "there should be 1 xattr name");
assert_eq!(
super::XATTR_NAME_BLOB_DIGEST,
XATTR_NAME_BLOB_DIGEST,
xattr_names.first().unwrap().as_encoded_bytes()
);
// The key should equal to the string-formatted b3 digest.
let val = xattr::get(&p, OsStr::from_bytes(super::XATTR_NAME_BLOB_DIGEST))
let val = xattr::get(&p, OsStr::from_bytes(XATTR_NAME_BLOB_DIGEST))
.expect("must succeed")
.expect("must be some");
assert_eq!(

View file

@ -9,9 +9,6 @@ pub mod fuse;
#[cfg(feature = "virtiofs")]
pub mod virtiofs;
#[cfg(test)]
mod tests;
pub use self::root_nodes::RootNodes;
use self::{
file_attr::ROOT_FILE_ATTR,