rlist_drivers/
driver_index.rsuse crate::onedrive::{OnedriveConfig, OnedriveDriver};
use crate::static_link::static_driver;
use rlist_driver_macro::rlist_driver_index;
use rlist_vfs::driver::{CloudDriver, GetVfs};
#[rlist_driver_index]
pub enum DriverIndex {
#[rlist_driver(name = "onedrive")]
OneDrive(OnedriveConfig),
#[rlist_driver(name = "static")]
Static(static_driver::StaticDir),
}
impl DriverIndex {
pub async fn create_instance(self) -> Box<dyn GetVfs> {
match self {
DriverIndex::OneDrive(config) => {
let driver = OnedriveDriver::load_config(config).await;
Box::new(OnedriveDriver::new(driver).await)
}
DriverIndex::Static(config) => {
let driver = static_driver::StaticDriver::load_config(config).await;
Box::new(static_driver::StaticDriver::new(driver).await)
}
}
}
}
#[cfg(test)]
mod test {
use crate::driver_index::DriverIndex::Static;
use rlist_vfs::VfsBasicMeta;
#[test]
fn test_des_static() {
let static_dir_json = r#"
{
"driver": "static",
"config": {
"name": "root",
"size": 2048,
"last_modified": "2024-04-22T12:00:00Z",
"files": [
{
"name": "example.txt",
"size": 1024,
"last_modified": "2024-04-21T11:00:00Z",
"links": [
"https://example.com/example.txt"
]
},
{
"name": "image.png",
"size": 512,
"last_modified": "2024-04-20T10:00:00Z",
"links": [
"https://example.com/image.png"
]
}
],
"subdirectories": [
{
"name": "docs",
"size": 512,
"last_modified": "2024-04-19T09:00:00Z",
"files": [
{
"name": "readme.md",
"size": 256,
"last_modified": "2024-04-18T08:00:00Z",
"links": [
"https://example.com/docs/readme.md"
]
}
],
"subdirectories": []
}
]
}
}
"#;
let result = serde_json::from_str::<super::DriverIndex>(static_dir_json);
assert!(result.is_ok());
let result = result.unwrap();
let result = match result {
Static(config) => config,
_ => panic!("Unexpected result"),
};
assert_eq!(result.name(), "root");
}
}