feat: validate configuration
This commit is contained in:
parent
ee7d7971be
commit
48c670f455
33 changed files with 1076 additions and 165 deletions
|
|
@ -23,15 +23,15 @@ impl TransmissionClient {
|
|||
let url = Url::parse(&url_str).wrap_err_with(|| format!("Invalid URL: {}", url_str))?;
|
||||
|
||||
let auth = BasicAuth {
|
||||
user: config.username.clone(),
|
||||
password: config.password.clone(),
|
||||
user: config.username.to_string(),
|
||||
password: config.password.to_string(),
|
||||
};
|
||||
|
||||
let client = TransClient::with_auth(url, auth);
|
||||
|
||||
Ok(TransmissionClient {
|
||||
client,
|
||||
download_dir: config.download_dir.clone(),
|
||||
download_dir: config.download_dir.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
use crate::app::Enableable;
|
||||
use crate::config::types::{AbsoluteDownloadDir, Host, Password, Port, Username};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Configuration for the Transmission action
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TransmissionConfig {
|
||||
pub enable: bool,
|
||||
pub host: String,
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
pub port: u16,
|
||||
pub download_dir: String,
|
||||
pub host: Host,
|
||||
pub username: Username,
|
||||
pub password: Password,
|
||||
pub port: Port,
|
||||
pub download_dir: AbsoluteDownloadDir,
|
||||
}
|
||||
|
||||
impl Enableable for TransmissionConfig {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
pub mod action;
|
||||
pub mod client;
|
||||
pub mod config;
|
||||
pub mod validation;
|
||||
|
||||
pub use action::TransmissionAction;
|
||||
pub use config::TransmissionConfig;
|
||||
|
|
|
|||
33
src/actions/transmission/validation.rs
Normal file
33
src/actions/transmission/validation.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use crate::actions::transmission::TransmissionConfig;
|
||||
use crate::config::Validate;
|
||||
use color_eyre::eyre::Result;
|
||||
|
||||
impl Validate for TransmissionConfig {
|
||||
fn validate(&self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::config::types::{AbsoluteDownloadDir, Host, Password, Port, Username};
|
||||
|
||||
fn create_valid_config() -> Result<TransmissionConfig> {
|
||||
Ok(TransmissionConfig {
|
||||
enable: true,
|
||||
host: Host::try_new("localhost")?,
|
||||
username: Username::try_new("user")?,
|
||||
password: Password::try_new("pass")?,
|
||||
port: Port::try_new(9091)?,
|
||||
download_dir: AbsoluteDownloadDir::try_new("/downloads")?,
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_valid_config() -> Result<()> {
|
||||
let config = create_valid_config()?;
|
||||
assert!(config.validate().is_ok());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue