no panic on failed torrent_add

This commit is contained in:
red 2020-08-27 21:28:50 +02:00
parent 70b6b822c4
commit 4e932deb49
3 changed files with 37 additions and 3 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "transmission-rpc"
version = "0.2.3"
version = "0.3.0"
authors = ["red <red.avtovo@gmail.com>"]
edition = "2018"
repository = "https://github.com/j0rsa/transmission-rpc"

View File

@ -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())
}
}
}
#[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(())
}
}

View File

@ -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<Torrent>
}
impl RpcResponseArgument for TorrentAdded{}