Skip to content

Commit

Permalink
chore: uncomment the unused code to address clippy error
Browse files Browse the repository at this point in the history
The backend-oss feature is nerver enabled, so uncomment test code.

Signed-off-by: Yang Kaiyong <[email protected]>
  • Loading branch information
Yang Kaiyong committed Jan 26, 2025
1 parent ed03daf commit 7b2e9dd
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 132 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CARGO ?= $(shell which cargo)
RUSTUP ?= $(shell which rustup)
CARGO_BUILD_GEARS = -v ~/.ssh/id_rsa:/root/.ssh/id_rsa -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry
SUDO = $(shell which sudo)
CARGO_COMMON ?=
CARGO_COMMON ?=

EXCLUDE_PACKAGES =
UNAME_M := $(shell uname -m)
Expand Down
1 change: 0 additions & 1 deletion rafs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ assert_matches = "1.5.0"
fusedev = ["fuse-backend-rs/fusedev"]
virtio-fs = ["fuse-backend-rs/virtiofs", "vm-memory/backend-mmap"]
vhost-user-fs = ["fuse-backend-rs/vhost-user-fs"]
backend-oss = ["nydus-storage/backend-oss"]

[package.metadata.docs.rs]
all-features = true
Expand Down
263 changes: 133 additions & 130 deletions rafs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,136 +891,139 @@ impl Layer for Rafs {
}
}

#[cfg(all(test, feature = "backend-oss"))]
pub(crate) mod tests {
use super::*;
use std::str::FromStr;

pub fn new_rafs_backend() -> Box<Rafs> {
let config = r#"
version = 2
id = "test"
[backend]
type = "oss"
[backend.oss]
endpoint = "test"
access_key_id = "test"
access_key_secret = "test"
bucket_name = "antsys-nydus"
object_prefix = "nydus_v2/"
scheme = "http"
[cache]
type = "filecache"
[cache.filecache]
work_dir = "."
[rafs]
mode = "direct"
validate = false
enable_xattr = true
[rafs.prefetch]
enable = true
threads = 10
batch_size = 131072
bandwidth_limit = 10485760
"#;
let root_dir = &std::env::var("CARGO_MANIFEST_DIR").expect("$CARGO_MANIFEST_DIR");
let mut source_path = PathBuf::from(root_dir);
source_path.push("../tests/texture/bootstrap/rafs-v5.boot");
let mountpoint = "/mnt";
let config = Arc::new(ConfigV2::from_str(config).unwrap());
let bootstrapfile = source_path.to_str().unwrap();
let (mut rafs, reader) = Rafs::new(&config, mountpoint, Path::new(bootstrapfile)).unwrap();
rafs.import(reader, Some(vec![std::path::PathBuf::new()]))
.unwrap();
Box::new(rafs)
}

#[test]
fn it_should_create_new_rafs_fs() {
let rafs = new_rafs_backend();
let attr = rafs.get_inode_attr(1).unwrap();
assert_eq!(attr.ino, 1);
assert_eq!(attr.blocks, 8);
assert_eq!(attr.uid, 0);
// Root inode mode must be 0755
assert_eq!(attr.mode & 0o777, 0o755);
}

#[test]
fn it_should_access() {
let rafs = new_rafs_backend();
let ctx = &Context {
gid: 0,
pid: 1,
uid: 0,
};
if rafs.access(ctx, 1, 0).is_err() {
panic!("failed to access inode 1");
}
}

#[test]
fn it_should_listxattr() {
let rafs = new_rafs_backend();
let ctx = &Context {
gid: 0,
pid: 1,
uid: 0,
};
match rafs.listxattr(ctx, 1, 0) {
Ok(reply) => match reply {
ListxattrReply::Count(c) => assert_eq!(c, 0),
_ => panic!(),
},
Err(_) => panic!("failed to access inode 1"),
}
}

#[test]
fn it_should_get_statfs() {
let rafs = new_rafs_backend();
let ctx = &Context {
gid: 0,
pid: 1,
uid: 0,
};
match rafs.statfs(ctx, 1) {
Ok(statfs) => {
assert_eq!(statfs.f_files, 43082);
assert_eq!(statfs.f_bsize, 512);
assert_eq!(statfs.f_namemax, 255);
assert_eq!(statfs.f_fsid, 1380009555);
assert_eq!(statfs.f_ffree, 0);
}
Err(_) => panic!("failed to statfs"),
}
}

#[test]
fn it_should_enable_xattr() {
let rafs = new_rafs_backend();
assert!(rafs.xattr_enabled);
assert!(rafs.xattr_supported());
}

#[test]
fn it_should_lookup_entry() {
let rafs = new_rafs_backend();
let ctx = &Context {
gid: 0,
pid: 1,
uid: 0,
};
match rafs.lookup(ctx, 1, &std::ffi::CString::new("/etc").unwrap()) {
Err(_e) => {
panic!("failed to lookup /etc from ino 1");
}
Ok(e) => {
assert_eq!(e.inode, 0);
}
}
}
}
// Uncomment the test since clippy will complain about unexpected-cfgs code.
// And the code is nerver used before.

// #[cfg(all(test, feature = "backend-oss"))]
// pub(crate) mod tests {
// use super::*;
// use std::str::FromStr;

// pub fn new_rafs_backend() -> Box<Rafs> {
// let config = r#"
// version = 2
// id = "test"
// [backend]
// type = "oss"
// [backend.oss]
// endpoint = "test"
// access_key_id = "test"
// access_key_secret = "test"
// bucket_name = "antsys-nydus"
// object_prefix = "nydus_v2/"
// scheme = "http"
// [cache]
// type = "filecache"
// [cache.filecache]
// work_dir = "."
// [rafs]
// mode = "direct"
// validate = false
// enable_xattr = true
// [rafs.prefetch]
// enable = true
// threads = 10
// batch_size = 131072
// bandwidth_limit = 10485760
// "#;
// let root_dir = &std::env::var("CARGO_MANIFEST_DIR").expect("$CARGO_MANIFEST_DIR");
// let mut source_path = PathBuf::from(root_dir);
// source_path.push("../tests/texture/bootstrap/rafs-v5.boot");
// let mountpoint = "/mnt";
// let config = Arc::new(ConfigV2::from_str(config).unwrap());
// let bootstrapfile = source_path.to_str().unwrap();
// let (mut rafs, reader) = Rafs::new(&config, mountpoint, Path::new(bootstrapfile)).unwrap();
// rafs.import(reader, Some(vec![std::path::PathBuf::new()]))
// .unwrap();
// Box::new(rafs)
// }

// #[test]
// fn it_should_create_new_rafs_fs() {
// let rafs = new_rafs_backend();
// let attr = rafs.get_inode_attr(1).unwrap();
// assert_eq!(attr.ino, 1);
// assert_eq!(attr.blocks, 8);
// assert_eq!(attr.uid, 0);
// // Root inode mode must be 0755
// assert_eq!(attr.mode & 0o777, 0o755);
// }

// #[test]
// fn it_should_access() {
// let rafs = new_rafs_backend();
// let ctx = &Context {
// gid: 0,
// pid: 1,
// uid: 0,
// };
// if rafs.access(ctx, 1, 0).is_err() {
// panic!("failed to access inode 1");
// }
// }

// #[test]
// fn it_should_listxattr() {
// let rafs = new_rafs_backend();
// let ctx = &Context {
// gid: 0,
// pid: 1,
// uid: 0,
// };
// match rafs.listxattr(ctx, 1, 0) {
// Ok(reply) => match reply {
// ListxattrReply::Count(c) => assert_eq!(c, 0),
// _ => panic!(),
// },
// Err(_) => panic!("failed to access inode 1"),
// }
// }

// #[test]
// fn it_should_get_statfs() {
// let rafs = new_rafs_backend();
// let ctx = &Context {
// gid: 0,
// pid: 1,
// uid: 0,
// };
// match rafs.statfs(ctx, 1) {
// Ok(statfs) => {
// assert_eq!(statfs.f_files, 43082);
// assert_eq!(statfs.f_bsize, 512);
// assert_eq!(statfs.f_namemax, 255);
// assert_eq!(statfs.f_fsid, 1380009555);
// assert_eq!(statfs.f_ffree, 0);
// }
// Err(_) => panic!("failed to statfs"),
// }
// }

// #[test]
// fn it_should_enable_xattr() {
// let rafs = new_rafs_backend();
// assert!(rafs.xattr_enabled);
// assert!(rafs.xattr_supported());
// }

// #[test]
// fn it_should_lookup_entry() {
// let rafs = new_rafs_backend();
// let ctx = &Context {
// gid: 0,
// pid: 1,
// uid: 0,
// };
// match rafs.lookup(ctx, 1, &std::ffi::CString::new("/etc").unwrap()) {
// Err(_e) => {
// panic!("failed to lookup /etc from ino 1");
// }
// Ok(e) => {
// assert_eq!(e.inode, 0);
// }
// }
// }
// }

#[cfg(test)]
mod tests {
Expand Down

0 comments on commit 7b2e9dd

Please sign in to comment.