From 4e932deb49a77e66cd979969c30514831aa14126 Mon Sep 17 00:00:00 2001 From: red Date: Thu, 27 Aug 2020 21:28:50 +0200 Subject: [PATCH] no panic on failed torrent_add --- Cargo.toml | 2 +- src/lib.rs | 36 +++++++++++++++++++++++++++++++++++- src/types/response.rs | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e2d68a5..9515590 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "transmission-rpc" -version = "0.2.3" +version = "0.3.0" authors = ["red "] edition = "2018" repository = "https://github.com/j0rsa/transmission-rpc" diff --git a/src/lib.rs b/src/lib.rs index e6f93c2..7964086 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -306,4 +306,38 @@ impl BodyString for reqwest::RequestBuilder { let body = rq.body().unwrap().as_bytes().unwrap(); Ok(std::str::from_utf8(body)?.to_string()) } -} \ No newline at end of file +} + +#[cfg(test)] +mod tests { + + use super::*; + use std::env; + use dotenv::dotenv; + + #[tokio::test] + pub async fn test_malformed_url() -> Result<()> { + dotenv().ok(); + env_logger::init(); + let url= env::var("TURL")?; + let basic_auth = BasicAuth{user: env::var("TUSER")?, password: env::var("TPWD")?}; + let client = TransClient::with_auth(&url, basic_auth); + info!("Client is ready!"); + let add: TorrentAddArgs = TorrentAddArgs { + filename: Some("https://releases.ubuntu.com/20.04/ubuntu-20.04-desktop-amd64.iso.torrentt".to_string()), + ..TorrentAddArgs::default() + }; + match client.torrent_add(add).await { + Ok(res) => { + println!("Add result: {:?}", &res.is_ok()); + println!("response: {:?}", &res); + assert!(!&res.is_ok()); + } + Err(e) => { + println!("Error: {:#?}", e); + } + } + + Ok(()) + } +} diff --git a/src/types/response.rs b/src/types/response.rs index 3bcb061..f39288a 100644 --- a/src/types/response.rs +++ b/src/types/response.rs @@ -96,6 +96,6 @@ impl RpcResponseArgument for Nothing {} #[derive(Deserialize, Debug, RustcEncodable)] pub struct TorrentAdded { #[serde(rename="torrent-added")] - pub torrent_added: Torrent + pub torrent_added: Option } impl RpcResponseArgument for TorrentAdded{} \ No newline at end of file