mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: Use PathBuf for local block source config
This commit is contained in:
@ -41,7 +41,7 @@ impl BlockSourceArgs {
|
|||||||
if let Some(bucket) = value.strip_prefix("s3://") {
|
if let Some(bucket) = value.strip_prefix("s3://") {
|
||||||
Ok(BlockSourceConfig::s3(bucket.to_string()).await)
|
Ok(BlockSourceConfig::s3(bucket.to_string()).await)
|
||||||
} else {
|
} else {
|
||||||
Ok(BlockSourceConfig::local(value.to_string()))
|
Ok(BlockSourceConfig::local(value.into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
use aws_config::BehaviorVersion;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
consts::DEFAULT_S3_BUCKET,
|
consts::DEFAULT_S3_BUCKET,
|
||||||
sources::{
|
sources::{
|
||||||
BlockSourceBoxed, CachedBlockSource, HlNodeBlockSource, LocalBlockSource, S3BlockSource,
|
BlockSourceBoxed, CachedBlockSource, HlNodeBlockSource, LocalBlockSource, S3BlockSource,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use std::{path::PathBuf, sync::Arc};
|
use aws_config::BehaviorVersion;
|
||||||
|
use std::{env::home_dir, path::PathBuf, sync::Arc};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct BlockSourceConfig {
|
pub struct BlockSourceConfig {
|
||||||
@ -17,7 +16,7 @@ pub struct BlockSourceConfig {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum BlockSourceType {
|
pub enum BlockSourceType {
|
||||||
S3 { bucket: String },
|
S3 { bucket: String },
|
||||||
Local { path: String },
|
Local { path: PathBuf },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BlockSourceConfig {
|
impl BlockSourceConfig {
|
||||||
@ -32,7 +31,7 @@ impl BlockSourceConfig {
|
|||||||
Self { source_type: BlockSourceType::S3 { bucket }, block_source_from_node: None }
|
Self { source_type: BlockSourceType::S3 { bucket }, block_source_from_node: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn local(path: String) -> Self {
|
pub fn local(path: PathBuf) -> Self {
|
||||||
Self { source_type: BlockSourceType::Local { path }, block_source_from_node: None }
|
Self { source_type: BlockSourceType::Local { path }, block_source_from_node: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::pseudo_peer::{prelude::*, BlockSourceType};
|
use crate::pseudo_peer::{prelude::*, BlockSourceType};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@ -10,8 +12,10 @@ async fn test_block_source_config_s3() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_block_source_config_local() {
|
async fn test_block_source_config_local() {
|
||||||
let config = BlockSourceConfig::local("/test/path".to_string());
|
let config = BlockSourceConfig::local("/test/path".into());
|
||||||
assert!(matches!(config.source_type, BlockSourceType::Local { path } if path == "/test/path"));
|
assert!(
|
||||||
|
matches!(config.source_type, BlockSourceType::Local { path } if path == Path::new("/test/path"))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user