Skip to content

Commit

Permalink
Fix various clippy warnings about unused code and variables
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Passaro <[email protected]>
  • Loading branch information
passaro committed Nov 6, 2023
1 parent faebbef commit 0bba1c7
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 66 deletions.
3 changes: 1 addition & 2 deletions mountpoint-s3/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ impl<Client: ObjectClient> UploadState<Client> {
/// Returns `None` if unable to find or parse the task status.
/// Not supported on macOS.
fn get_tgid(pid: u32) -> Option<u32> {
#[cfg(not(target_os = "macos"))]
{
if cfg!(not(target_os = "macos")) {
use std::fs::File;
use std::io::{BufRead, BufReader};

Expand Down
1 change: 0 additions & 1 deletion mountpoint-s3/src/inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,6 @@ mod tests {
}

let prefix = Prefix::new(prefix).expect("valid prefix");
let ts = OffsetDateTime::now_utc();
let ttl = if cached {
std::time::Duration::from_secs(60 * 60 * 24 * 7) // 7 days should be enough
} else {
Expand Down
5 changes: 4 additions & 1 deletion mountpoint-s3/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::time::Duration;
use anyhow::{anyhow, Context as _};
use clap::{value_parser, Parser};
use fuser::{MountOption, Session};
use mountpoint_s3::fs::{CacheConfig, S3FilesystemConfig};
use mountpoint_s3::fs::S3FilesystemConfig;
use mountpoint_s3::fuse::session::FuseSession;
use mountpoint_s3::fuse::S3FuseFilesystem;
use mountpoint_s3::instance::InstanceInfo;
Expand Down Expand Up @@ -504,6 +504,8 @@ fn mount(args: CliArgs) -> anyhow::Result<FuseSession> {

#[cfg(feature = "caching")]
{
use mountpoint_s3::fs::CacheConfig;

if args.enable_metadata_caching {
// TODO: Review default for TTL
let metadata_cache_ttl = args.metadata_cache_ttl.unwrap_or(Duration::from_secs(3600));
Expand Down Expand Up @@ -632,6 +634,7 @@ fn parse_bucket_name(bucket_name: &str) -> anyhow::Result<String> {
Ok(bucket_name.to_owned())
}

#[cfg(feature = "caching")]
fn parse_duration_seconds(seconds_str: &str) -> anyhow::Result<Duration> {
let seconds = seconds_str.parse()?;
let duration = Duration::from_secs(seconds);
Expand Down
57 changes: 0 additions & 57 deletions mountpoint-s3/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use aws_sdk_s3::config::Region;
use aws_sdk_s3::primitives::ByteStream;
use fuser::{FileAttr, FileType};
use futures::executor::ThreadPool;
use mountpoint_s3::fs::{self, DirectoryEntry, DirectoryReplier, ReadReplier, ToErrno};
Expand All @@ -8,10 +6,7 @@ use mountpoint_s3::{S3Filesystem, S3FilesystemConfig};
use mountpoint_s3_client::mock_client::{MockClient, MockClientConfig};
use mountpoint_s3_client::ObjectClient;
use mountpoint_s3_crt::common::rust_log_adapter::RustLogAdapter;
use rand::rngs::OsRng;
use rand::RngCore;
use std::collections::VecDeque;
use std::future::Future;
use std::sync::Arc;

pub fn make_test_filesystem(
Expand Down Expand Up @@ -42,58 +37,6 @@ where
S3Filesystem::new(client, runtime, bucket, prefix, config)
}

pub fn get_test_bucket_and_prefix(test_name: &str) -> (String, String) {
let bucket = std::env::var("S3_BUCKET_NAME").expect("Set S3_BUCKET_NAME to run integration tests");

// Generate a random nonce to make sure this prefix is truly unique
let nonce = OsRng.next_u64();

// Prefix always has a trailing "/" to keep meaning in sync with the S3 API.
let prefix = std::env::var("S3_BUCKET_TEST_PREFIX").unwrap_or(String::from("mountpoint-test/"));
assert!(prefix.ends_with('/'), "S3_BUCKET_TEST_PREFIX should end in '/'");

let prefix = format!("{prefix}{test_name}/{nonce}/");

(bucket, prefix)
}

pub fn get_test_bucket_forbidden() -> String {
std::env::var("S3_FORBIDDEN_BUCKET_NAME").expect("Set S3_FORBIDDEN_BUCKET_NAME to run integration tests")
}

pub fn get_test_region() -> String {
std::env::var("S3_REGION").expect("Set S3_REGION to run integration tests")
}

pub fn get_subsession_iam_role() -> String {
std::env::var("S3_SUBSESSION_IAM_ROLE").expect("Set S3_SUBSESSION_IAM_ROLE to run integration tests")
}

pub fn create_objects(bucket: &str, prefix: &str, region: &str, key: &str, value: &[u8]) {
let config = tokio_block_on(aws_config::from_env().region(Region::new(region.to_string())).load());
let sdk_client = aws_sdk_s3::Client::new(&config);
let full_key = format!("{prefix}{key}");
tokio_block_on(async move {
sdk_client
.put_object()
.bucket(bucket)
.key(full_key)
.body(ByteStream::from(value.to_vec()))
.send()
.await
.unwrap()
});
}

pub fn tokio_block_on<F: Future>(future: F) -> F::Output {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_io()
.enable_time()
.build()
.unwrap();
runtime.block_on(future)
}

#[track_caller]
pub fn assert_attr(attr: FileAttr, ftype: FileType, size: u64, uid: u32, gid: u32, perm: u16) {
assert_eq!(attr.kind, ftype);
Expand Down
5 changes: 2 additions & 3 deletions mountpoint-s3/tests/fuse_tests/fork_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ use std::process::Stdio;
use std::{path::PathBuf, process::Command};
use test_case::test_case;

use crate::common::{
use crate::fuse_tests::{
create_objects, get_subsession_iam_role, get_test_bucket_and_prefix, get_test_bucket_forbidden, get_test_region,
tokio_block_on,
read_dir_to_entry_names, tokio_block_on,
};
use crate::fuse_tests::read_dir_to_entry_names;

const MAX_WAIT_DURATION: std::time::Duration = std::time::Duration::from_secs(10);

Expand Down
60 changes: 58 additions & 2 deletions mountpoint-s3/tests/fuse_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ mod write_test;
use std::ffi::OsStr;
use std::fs::ReadDir;

use aws_sdk_s3::primitives::ByteStream;
use aws_sdk_sts::config::Region;
use fuser::{BackgroundSession, MountOption, Session};
use futures::Future;
use mountpoint_s3::fuse::S3FuseFilesystem;
use mountpoint_s3::prefix::Prefix;
use mountpoint_s3::S3FilesystemConfig;
use mountpoint_s3_client::types::PutObjectParams;
use rand::RngCore;
use rand_chacha::rand_core::OsRng;
use tempfile::TempDir;

pub trait TestClient: Send {
Expand Down Expand Up @@ -189,8 +194,6 @@ mod mock_session {

#[cfg(feature = "s3_tests")]
mod s3_session {
use crate::common::{get_test_bucket_and_prefix, get_test_region};

use super::*;

use std::future::Future;
Expand Down Expand Up @@ -394,6 +397,7 @@ mod s3_session {
}
}
}

/// Take a `read_dir` iterator and return the entry names
pub fn read_dir_to_entry_names(read_dir_iter: ReadDir) -> Vec<String> {
read_dir_iter
Expand All @@ -408,3 +412,55 @@ pub fn read_dir_to_entry_names(read_dir_iter: ReadDir) -> Vec<String> {
})
.collect::<Vec<_>>()
}

pub fn get_test_bucket_and_prefix(test_name: &str) -> (String, String) {
let bucket = std::env::var("S3_BUCKET_NAME").expect("Set S3_BUCKET_NAME to run integration tests");

// Generate a random nonce to make sure this prefix is truly unique
let nonce = OsRng.next_u64();

// Prefix always has a trailing "/" to keep meaning in sync with the S3 API.
let prefix = std::env::var("S3_BUCKET_TEST_PREFIX").unwrap_or(String::from("mountpoint-test/"));
assert!(prefix.ends_with('/'), "S3_BUCKET_TEST_PREFIX should end in '/'");

let prefix = format!("{prefix}{test_name}/{nonce}/");

(bucket, prefix)
}

pub fn get_test_bucket_forbidden() -> String {
std::env::var("S3_FORBIDDEN_BUCKET_NAME").expect("Set S3_FORBIDDEN_BUCKET_NAME to run integration tests")
}

pub fn get_test_region() -> String {
std::env::var("S3_REGION").expect("Set S3_REGION to run integration tests")
}

pub fn get_subsession_iam_role() -> String {
std::env::var("S3_SUBSESSION_IAM_ROLE").expect("Set S3_SUBSESSION_IAM_ROLE to run integration tests")
}

pub fn create_objects(bucket: &str, prefix: &str, region: &str, key: &str, value: &[u8]) {
let config = tokio_block_on(aws_config::from_env().region(Region::new(region.to_string())).load());
let sdk_client = aws_sdk_s3::Client::new(&config);
let full_key = format!("{prefix}{key}");
tokio_block_on(async move {
sdk_client
.put_object()
.bucket(bucket)
.key(full_key)
.body(ByteStream::from(value.to_vec()))
.send()
.await
.unwrap()
});
}

pub fn tokio_block_on<F: Future>(future: F) -> F::Output {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_io()
.enable_time()
.build()
.unwrap();
runtime.block_on(future)
}

0 comments on commit 0bba1c7

Please sign in to comment.